Display LGPL and GPL content to users



  • Hi all :-)

    My application is close to deployment now. Since I use the LGPL licence of the Qt lib, one of the requirements is to give a copy of both GPL/LGPL licences to users. I want these licence files to be embedded within the app, not as side text files. As a consequence, I include two text files as declared resources in a .qrc file (COPYING.txt and COPYING.LESSER.txt). My GUI has two buttons appearing at the beginning. If the user clicks on it, I want to show the content of the files. Two options:

    1. Load files from the resources and use QDesktopServices::openUrl(). This seems to be the easiest solution because the files would show in the default text editor of the OS (WIN). As far as I understood from my readings, this is not possible because the resource files are not in the arborescence of the OS. Do you confirm ? Any workaround ? (I'd like to avoid writing a temp file)
    2. Use a textstream a feed a QMessage or a QTextEditor with this. The problem is I have to use readLine() in a while loop. How to feed the widgets with such streams ?

    By advance, thanks a lot for your help.


  • Lifetime Qt Champion

    Hi,

    1. Without copying the file to a temporary file you can't.
    2. Why not read the complete file in one with QFile and set its content to e.g. a QLabel ?


  • @SGaist Hi, and thanks for your answers.

    1. OK, cristal clear confirmation of what I expected
    2. Will give it a try and let you know. I didn't realize that QFile could be used directly.

    Stay tuned for final results if interested.



  • @SGaist
    Test 2) but, fore some reason I don't understand, the textedit disappears immediately ???

    void disclaimerPage::showGPL()
    {
        QTextEdit textWindow;
        textWindow.setGeometry(100,100,200,400);
        textWindow.setReadOnly(true);
    
        QString text;
    
        QResource common("://licences/COPYING.txt");
        QFile commonFile(common.absoluteFilePath());
    
        if(commonFile.open(QFile::ReadOnly | QFile::Text))
            {
                 text = commonFile.readAll();
                 commonFile.close();
            }
        else text = "Cannot open file !";
    
        textWindow.setText(text);
        textWindow.show();
    }
    

    This code is a slot of a qpushbutton within a qwizard page... I think there's something I don't understand with parent and child windows :=(

    Any idea would be appreciated



  • @SGaist Problem solved, I missed the basics. Many thanks

    void disclaimerPage::showGPL()
    {
        QTextEdit *textBox = new QTextEdit();
        textBox->setGeometry(100,100,200,400);
        textBox->setReadOnly(true);
    
        QString text;
    
        QResource common("://licences/COPYING.txt");
        QFile commonFile(common.absoluteFilePath());
    
        if(commonFile.open(QFile::ReadOnly | QFile::Text))
            {
                 text = commonFile.readAll();
                 commonFile.close();
            }
        else text = "Impossible d'ouvrir le fichier !";
    
        textBox->setText(text);
        textBox->show();
    }
    

  • Lifetime Qt Champion

    Except now you have a memory leak.

    You should add textBox->setAttribute(Qt::WA_DeleteOnClose);to ensure it gets destroyed properly when the users closes it.

    The other possibility is rollback to your original implementation but call exec in place of show. That will block your application while the user reads the file(s)



  • @SGaist one more good point. Thx.



  • @SGaist one more problem, the file doesn't display properly (utf-8 encoding, french language). Since readAll() returns a QByteArray, do you know a way to solve the issue ???


  • Lifetime Qt Champion

    You can use the QString::fromUtf8


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.