-
UID:143742
-
- 注册时间2013-05-13
- 最后登录2013-08-15
- 在线时间13小时
-
- 发帖18
- 搜Ta的帖子
- 精华0
- 金钱190
- 威望28
- 贡献值0
- 好评度18
-
访问TA的空间加好友用道具
|
下面是该程序的Qt部分源代码: - main.cpp
- #include "MainWindow.h"
- #include <QApplication>
- int main( int argc, char **argv){
- QApplication qappMainApp( argc, argv );
- MainWindow mwMyMainWindow;
- mwMyMainWindow.show();
- return qappMainApp.exec();
- }
- MainWindow.cpp
- #include "MainWindow.h"
- #include "..\__DESAlgorithm.h"
- MainWindow::MainWindow(){
- QTextCodec::setCodecForTr( QTextCodec::codecForName( "UTF-8" ) );
- pqlMainLayout = new QVBoxLayout( this );
- setLayout( pqlMainLayout );
- resize( 600, 400 );
- CreatMenuBar();
- CreatLayouts();
-
- }
- MainWindow::~MainWindow(){
- ;
- }
- void MainWindow::CreatMenuBar(){
- pmbMenuBar = new QMenuBar( this );
- setMenuBar( pmbMenuBar );
-
- pqmFile = new QMenu( tr("文件(&F)"), this );
- pmbMenuBar->addMenu( pqmFile );
-
- pqaExit = pqmFile->addAction( tr("退出(&X)") );
- pqaExit->setShortcut( tr("Ctrl+Q") );
- connect( pqaExit, SIGNAL( triggered() ), this, SLOT( close() ) );
-
- pqmHelp = new QMenu( tr("帮助(&H)"), this);
- pmbMenuBar->addMenu( pqmHelp );
-
- pqaAbout = pqmHelp->addAction( tr("关于(&A)") );
- pqaAbout->setShortcut( tr("Ctrl+A") );
- connect( pqaAbout, SIGNAL( triggered() ), this, SLOT( About() ) );
-
- pqaAboutQt = pqmHelp->addAction( tr("关于Qt(&Q)") );
- pqaAboutQt->setShortcut( tr("Ctrl+T") );
- connect( pqaAboutQt, SIGNAL( triggered() ), this, SLOT( AboutQt() ) );
- }
- void MainWindow::CreatLayouts(){
- pqwCentralWidget = new QWidget( this );
- setCentralWidget( pqwCentralWidget );
- pqlMainLayout = new QVBoxLayout( this );
- pqwCentralWidget -> setLayout( pqlMainLayout );
-
- pqgbTextBox = new QGroupBox( tr("明文(&T)"), this );
- pqlMainLayout->addWidget( pqgbTextBox );
- pqlTextLayout = new QHBoxLayout();
- pqgbTextBox->setLayout( pqlTextLayout );
- pqteText = new QTextEdit;
- pqlTextLayout->addWidget( pqteText );
-
- pqgbCipherTextBox = new QGroupBox( tr("密文(&C)"), this );
- pqlMainLayout->addWidget( pqgbCipherTextBox );
- pqlCipherTextLayout = new QHBoxLayout();
- pqgbCipherTextBox->setLayout( pqlCipherTextLayout );
- pqteCipherText = new QTextEdit;
- pqlCipherTextLayout->addWidget( pqteCipherText );
-
- pqwKeyWidget = new QWidget();
- pqlMainLayout->addWidget( pqwKeyWidget );
- pqlKeyLayout = new QHBoxLayout();
- pqwKeyWidget->setLayout( pqlKeyLayout );
- pqlKeyLabel= new QLabel( tr("密钥(&K)") );
- pqlKeyLayout->addWidget( pqlKeyLabel );
- pqleKey = new QLineEdit();
- pqlKeyLayout->addWidget( pqleKey );
-
- pqdbbButtonBox = new QDialogButtonBox( this );
- pqlMainLayout->addWidget( pqdbbButtonBox );
- pqpbEncryption = pqdbbButtonBox->addButton( tr("加密(&E)"), QDialogButtonBox::ActionRole );
- pqpbDecryption = pqdbbButtonBox->addButton( tr("解密(&D)"), QDialogButtonBox::ActionRole );
- connect( pqpbEncryption, SIGNAL( clicked() ), this, SLOT( Encryption() ) );
- connect( pqpbDecryption, SIGNAL( clicked() ), this, SLOT( Decryption() ) );
- }
- void MainWindow::About(){
- QMessageBox::about(
- this,
- tr("关于本程序"),
- tr("<p>这<b>Qt</b>应用程序部分源代码使用了Qt库。</p>")
- );
- }
- void MainWindow::AboutQt(){
- QMessageBox::aboutQt(
- this,
- tr("关于 Qt")
- );
- }
- void MainWindow::Encryption(){
- QString
- qsText = pqteText->toPlainText()/*从明文文本框获取输入的明文*/,
- qsKey = pqleKey->text()/*从密钥文本框获取输出的密钥*/
- ;
- QByteArray
- qbaText = qsText.toUtf8()/*将目标转换为UTF-8串*/,
- qbaKey = qsKey.toUtf8()/*将密钥转换为UTF-8串*/
- ;
- des::CString * c_string_text = des::c_string_new( qbaText, -1 );
- des::CString * c_string_key = des::c_string_new( qbaKey, -1);
- //加密得到密文
- des::CString * c_string_target = encryption_fun ( c_string_text, c_string_key, encryption/*加密*/ );
- pqteCipherText->setPlainText ( QString::fromUtf8( c_string_target->str )/*将UTF-8串转为QString*/ );
- des::c_string_free ( c_string_text );
- des::c_string_free ( c_string_key );
- des::c_string_free ( c_string_target );
- }
- void MainWindow::Decryption(){
- QString
- qsText = pqteCipherText->toPlainText()/*从密文文本框获取输入的密文*/,
- qsKey = pqleKey->text()/*从密钥文本框获取输出的密钥*/
- ;
- QByteArray
- qbaText = qsText.toUtf8()/*将目标转换为UTF-8串*/,
- qbaKey = qsKey.toUtf8()/*将密钥转换为UTF-8串*/
- ;
- des::CString * c_string_text = des::c_string_new( qbaText, -1 );
- des::CString * c_string_key = des::c_string_new( qbaKey, -1);
- //解密得到明文
- des::CString * c_string_target = encryption_fun ( c_string_text, c_string_key, decryption/*解密*/ );
- pqteText->setPlainText ( QString::fromUtf8( c_string_target->str )/*将UTF-8串转为QString*/ );
- des::c_string_free ( c_string_text );
- des::c_string_free ( c_string_key );
- des::c_string_free ( c_string_target );
- }
- MainWindow.h
- #include <QMainWindow>
- #include <QLabel>
- #include <QGroupBox>
- #include <QAction>
- #include <QLayout>
- #include <QMenuBar>
- #include <QTextEdit>
- #include <QLineEdit>
- #include <QMessageBox>
- #include <QDialogButtonBox>
- #include <QTextCodec>
- #include <QPushButton>
- #include <QString>
- #include <QByteArray>
- class MainWindow : public QMainWindow{
- Q_OBJECT
- public:
- MainWindow(void);
- ~MainWindow(void);
- protected:
-
- private slots:
- void About();
- void AboutQt();
- void Encryption();
- void Decryption();
-
- private:
- void CreatMenuBar();
- void CreatLayouts();
- QWidget * pqwCentralWidget;
- QLayout * pqlMainLayout;
- QMenuBar * pmbMenuBar;
- QMenu * pqmFile, * pqmHelp;
- QAction * pqaExit, * pqaAbout, * pqaAboutQt;
- QGroupBox * pqgbTextBox, * pqgbCipherTextBox;
- QLayout * pqlTextLayout, * pqlCipherTextLayout, * pqlKeyLayout;
- QWidget * pqwKeyWidget;
- QLabel * pqlKeyLabel;
- QTextEdit * pqteText, * pqteCipherText;
- QLineEdit * pqleKey;
- QDialogButtonBox * pqdbbButtonBox;
- QPushButton * pqpbEncryption, * pqpbDecryption;
- };
整个程序 闭源的 部分是头 文件: "..\__DESAlgorithm.h"。本程序使用了它包含的命名空间和函数和变量类型: :des、CString 、c_string_new()、encryption_fun();等等。 大家来讨论讨论,在不把私有的头文件开源的情况下,遵守 LGPL版本2.1, 发布该 软件呢? 我记得可以用一个“容器”(函数),把程序设计到Qt的代码容纳起来,届时只需要开源该容器即可。 其次,我的那个私有的头文件, 1、其实是不是可以把定义和实现分拆为: __DESAlgorithm.h和 __DESAlgorithm.cpp呢?这样,只需要开源头文件,但是细节cpp就闭源,只提供.o文件供 其他人连接 编译。 2、或者把我的头文件编译为动态链接库,然后就可以呢(说实话,我也不会弄动态链接库。。) 下面是程序效果图:
|