• 5691阅读
  • 6回复

如何发布一个部分使用了Qt的闭源软件 [复制链接]

上一主题 下一主题
离线gameboy70949
 
只看楼主 倒序阅读 楼主  发表于: 2013-05-21
下面是该程序的Qt部分源代码:
  1. main.cpp
  2. #include "MainWindow.h"
  3. #include <QApplication>
  4. int main( int argc, char **argv){
  5.     QApplication qappMainApp( argc, argv );
  6.     MainWindow mwMyMainWindow;
  7.     mwMyMainWindow.show();
  8.     return qappMainApp.exec();
  9. }
  1. MainWindow.cpp
  2. #include "MainWindow.h"
  3. #include "..\__DESAlgorithm.h"
  4. MainWindow::MainWindow(){
  5.     QTextCodec::setCodecForTr( QTextCodec::codecForName( "UTF-8" ) );
  6.     pqlMainLayout = new QVBoxLayout( this );
  7.     setLayout( pqlMainLayout );
  8.     resize( 600, 400 );
  9.     CreatMenuBar();
  10.     CreatLayouts();
  11.     
  12. }
  13. MainWindow::~MainWindow(){
  14.     ;
  15. }
  16. void MainWindow::CreatMenuBar(){
  17.     pmbMenuBar = new QMenuBar( this );
  18.     setMenuBar( pmbMenuBar );
  19.     
  20.     pqmFile = new QMenu( tr("文件(&F)"), this );
  21.     pmbMenuBar->addMenu( pqmFile );
  22.     
  23.     pqaExit = pqmFile->addAction( tr("退出(&X)") );
  24.     pqaExit->setShortcut( tr("Ctrl+Q") );
  25.     connect( pqaExit, SIGNAL( triggered() ), this, SLOT( close() ) );
  26.     
  27.     pqmHelp = new QMenu( tr("帮助(&H)"), this);
  28.     pmbMenuBar->addMenu( pqmHelp );
  29.     
  30.     pqaAbout = pqmHelp->addAction( tr("关于(&A)") );
  31.     pqaAbout->setShortcut( tr("Ctrl+A") );
  32.     connect( pqaAbout, SIGNAL( triggered() ), this, SLOT( About() ) );
  33.     
  34.     pqaAboutQt = pqmHelp->addAction( tr("关于Qt(&Q)") );
  35.     pqaAboutQt->setShortcut( tr("Ctrl+T") );
  36.     connect( pqaAboutQt, SIGNAL( triggered() ), this, SLOT( AboutQt() ) );
  37. }
  38. void MainWindow::CreatLayouts(){
  39.     pqwCentralWidget = new QWidget( this );
  40.     setCentralWidget( pqwCentralWidget );
  41.     pqlMainLayout = new QVBoxLayout( this );
  42.     pqwCentralWidget -> setLayout( pqlMainLayout );
  43.     
  44.     pqgbTextBox = new QGroupBox( tr("明文(&T)"), this );
  45.     pqlMainLayout->addWidget( pqgbTextBox );
  46.     pqlTextLayout = new QHBoxLayout();
  47.     pqgbTextBox->setLayout( pqlTextLayout );
  48.     pqteText = new QTextEdit;
  49.     pqlTextLayout->addWidget( pqteText );
  50.     
  51.     pqgbCipherTextBox = new QGroupBox( tr("密文(&C)"), this );
  52.     pqlMainLayout->addWidget( pqgbCipherTextBox );
  53.     pqlCipherTextLayout = new QHBoxLayout();
  54.     pqgbCipherTextBox->setLayout( pqlCipherTextLayout );
  55.     pqteCipherText = new QTextEdit;
  56.     pqlCipherTextLayout->addWidget( pqteCipherText );
  57.     
  58.     pqwKeyWidget = new QWidget();
  59.     pqlMainLayout->addWidget( pqwKeyWidget );
  60.     pqlKeyLayout = new QHBoxLayout();
  61.     pqwKeyWidget->setLayout( pqlKeyLayout );
  62.     pqlKeyLabel= new QLabel( tr("密钥(&K)") );
  63.     pqlKeyLayout->addWidget( pqlKeyLabel );
  64.     pqleKey = new QLineEdit();
  65.     pqlKeyLayout->addWidget( pqleKey );
  66.     
  67.     pqdbbButtonBox = new QDialogButtonBox( this );
  68.     pqlMainLayout->addWidget( pqdbbButtonBox );
  69.     pqpbEncryption = pqdbbButtonBox->addButton( tr("加密(&E)"), QDialogButtonBox::ActionRole );
  70.     pqpbDecryption = pqdbbButtonBox->addButton( tr("解密(&D)"), QDialogButtonBox::ActionRole );
  71.     connect( pqpbEncryption, SIGNAL( clicked() ), this, SLOT( Encryption() ) );
  72.     connect( pqpbDecryption, SIGNAL( clicked() ), this, SLOT( Decryption() ) );
  73. }
  74. void MainWindow::About(){
  75.     QMessageBox::about(
  76.         this,
  77.         tr("关于本程序"),
  78.         tr("<p>这<b>Qt</b>应用程序部分源代码使用了Qt库。</p>")
  79.     );
  80. }
  81. void MainWindow::AboutQt(){
  82.     QMessageBox::aboutQt(
  83.         this,
  84.         tr("关于 Qt")
  85.     );
  86. }
  87. void MainWindow::Encryption(){
  88.     QString
  89.         qsText = pqteText->toPlainText()/*从明文文本框获取输入的明文*/,
  90.         qsKey = pqleKey->text()/*从密钥文本框获取输出的密钥*/
  91.         ;
  92.     QByteArray
  93.         qbaText = qsText.toUtf8()/*将目标转换为UTF-8串*/,
  94.         qbaKey = qsKey.toUtf8()/*将密钥转换为UTF-8串*/
  95.         ;
  96.     des::CString * c_string_text = des::c_string_new( qbaText, -1 );
  97.     des::CString * c_string_key = des::c_string_new( qbaKey, -1);
  98.     //加密得到密文
  99.     des::CString * c_string_target = encryption_fun ( c_string_text, c_string_key, encryption/*加密*/ );
  100.     pqteCipherText->setPlainText ( QString::fromUtf8( c_string_target->str )/*将UTF-8串转为QString*/ );
  101.     des::c_string_free ( c_string_text );
  102.     des::c_string_free ( c_string_key );
  103.     des::c_string_free ( c_string_target );
  104. }
  105. void MainWindow::Decryption(){
  106.         QString
  107.         qsText = pqteCipherText->toPlainText()/*从密文文本框获取输入的密文*/,
  108.         qsKey = pqleKey->text()/*从密钥文本框获取输出的密钥*/
  109.         ;
  110.     QByteArray
  111.         qbaText = qsText.toUtf8()/*将目标转换为UTF-8串*/,
  112.         qbaKey = qsKey.toUtf8()/*将密钥转换为UTF-8串*/
  113.         ;
  114.     des::CString * c_string_text = des::c_string_new( qbaText, -1 );
  115.     des::CString * c_string_key = des::c_string_new( qbaKey, -1);
  116.     //解密得到明文
  117.     des::CString * c_string_target = encryption_fun ( c_string_text, c_string_key, decryption/*解密*/ );
  118.     pqteText->setPlainText ( QString::fromUtf8( c_string_target->str )/*将UTF-8串转为QString*/ );
  119.     des::c_string_free ( c_string_text );
  120.     des::c_string_free ( c_string_key );
  121.     des::c_string_free ( c_string_target );
  122. }
  1. MainWindow.h
  2. #include <QMainWindow>
  3. #include <QLabel>
  4. #include <QGroupBox>
  5. #include <QAction>
  6. #include <QLayout>
  7. #include <QMenuBar>
  8. #include <QTextEdit>
  9. #include <QLineEdit>
  10. #include <QMessageBox>
  11. #include <QDialogButtonBox>
  12. #include <QTextCodec>
  13. #include <QPushButton>
  14. #include <QString>
  15. #include <QByteArray>
  16. class MainWindow : public QMainWindow{
  17.     Q_OBJECT
  18. public:
  19.     MainWindow(void);
  20.     ~MainWindow(void);
  21. protected:
  22.     
  23. private slots:
  24.     void About();
  25.     void AboutQt();
  26.     void Encryption();
  27.     void Decryption();
  28.     
  29. private:
  30.     void CreatMenuBar();
  31.     void CreatLayouts();
  32.     QWidget * pqwCentralWidget;
  33.     QLayout * pqlMainLayout;
  34.     QMenuBar * pmbMenuBar;
  35.     QMenu * pqmFile, * pqmHelp;
  36.     QAction * pqaExit, * pqaAbout, * pqaAboutQt;
  37.     QGroupBox * pqgbTextBox, * pqgbCipherTextBox;
  38.     QLayout * pqlTextLayout, * pqlCipherTextLayout, * pqlKeyLayout;
  39.     QWidget * pqwKeyWidget;
  40.     QLabel * pqlKeyLabel;
  41.     QTextEdit * pqteText, * pqteCipherText;
  42.     QLineEdit * pqleKey;
  43.     QDialogButtonBox * pqdbbButtonBox;
  44.     QPushButton * pqpbEncryption, * pqpbDecryption;
  45. };
整个程序闭源部分是头文件"..\__DESAlgorithm.h"。本程序使用了它包含的命名空间和函数和变量类型::des、CString 、c_string_new()、encryption_fun();等等。
大家来讨论讨论,在不把私有的头文件开源的情况下,遵守LGPL版本2.1,发布软件呢?
我记得可以用一个“容器”(函数),把程序设计到Qt的代码容纳起来,届时只需要开源该容器即可。
其次,我的那个私有的头文件,
1、其实是不是可以把定义和实现分拆为:__DESAlgorithm.h__DESAlgorithm.cpp呢?这样,只需要开源头文件,但是细节cpp就闭源,只提供.o文件供其他人连接编译
2、或者把我的头文件编译为动态链接库,然后就可以呢(说实话,我也不会弄动态链接库。。)


下面是程序效果图:

离线dbzhang800

只看该作者 1楼 发表于: 2013-05-21
LGPL没要求你公开你自己写的代码。只要你没有修改Qt自身的源代码,你不需要公开任何代码。
离线gameboy70949
只看该作者 2楼 发表于: 2013-05-21
回 1楼(dbzhang800) 的帖子
但是我使用了Qt的源代码,那么这部分不需要公开么?
离线dbzhang800

只看该作者 3楼 发表于: 2013-05-21
Re:回 1楼(dbzhang800) 的帖子
引用第2楼gameboy70949于2013-05-21 19:10发表的 回 1楼(dbzhang800) 的帖子 :
但是我使用了Qt的源代码,那么这部分不需要公开么?

你是说你打开Qt的源代码,从某个.cpp中拷贝了一段代码用在了你自己的 .cpp 文件中??
离线gameboy70949
只看该作者 4楼 发表于: 2013-05-21
回 3楼(dbzhang800) 的帖子
不是,我只是包含了Qt的头文件,使用了它的类和数据结构和函数。并没有修改Qt源代码。。
离线dbzhang800

只看该作者 5楼 发表于: 2013-05-22
Re:回 3楼(dbzhang800) 的帖子
引用第4楼gameboy70949于2013-05-21 22:24发表的 回 3楼(dbzhang800) 的帖子 :
不是,我只是包含了Qt的头文件,使用了它的类和数据结构和函数。并没有修改Qt源代码。。

你不需要公开任何东西
离线gameboy70949
只看该作者 6楼 发表于: 2013-05-22
回 5楼(dbzhang800) 的帖子
哦。知道。
快速回复
限100 字节
 
上一个 下一个