How to use KDE Frameworks with Qt Creator



  • On Linux (Ubuntu) there are two ways to install Qt, first is to use apt (sudo apt install qt5-default) and the other one is to download Qt from the official website. Now when you install using the first way Qt is installed by defualt /usr/lib and the second way in the home folder (or in /opt if you ran the installed with administrator privileges).
    Now I would like to integrate KDE Frameworks 5 in my project so on the official website it is suggested to use:

    sudo apt install framework

    And then you can just include that in your project by QT += framework. The problem is I installed Qt using the second way (downloading from the website) and as a result Qt Creator always return Project ERROR: Unknown module(s) in QT: framework. This I believe is because Qt doesn't seem to be aware of the fact that the modules are in /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules/ instead it probably looks for them somewhere else.
    How do I solve this problem with a permanent solution? I cannot install Qt using apt because I would like to use the latest version which usually in not immediately available in the default repositories.


  • Moderators

    I suppose you need to build from source https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source

    Or (hacky!) move the files from /usr/lib into your /opt installation.

    BTW. You don't have to run Qt installer as administrator. Local, normal-user installation is also fine, and usually easier to work with.

    PS. You may also achieve some progress by using qt.conf https://doc.qt.io/qt-5/qt-conf.html although I doubt it.



  • Ok so for example I cloned KSyntaxHighlighting project from github and then installed kdesrc and built using kdesrc-build syntax-highlighting --include-dependencies (see here https://community.kde.org/Get_Involved/development#Set_up_kdesrc-build). Now the build succeded however how I do include the module in Qt Creator??? It still says module not found because I assume it's not looking in the correct directory (I can see the build folder in $HOME/kde/build)



  • @daljit97 said in How to use KDE Frameworks with Qt Creator:

    QT += framework

    1. Are you sure that build KDE framework does indeed make a Qt module?
    2. And more important, does KDE install the module(s) where Qt looks for modules?

    I guess that what you have built for KDE are indeed and can be used as external libraries within a Qt project...

    LIBS += -L/path/to/your/library/ -lmylibrary
    


  • @Pablo-J.-Rogina said in How to use KDE Frameworks with Qt Creator:

    Are you sure that build KDE framework does indeed make a Qt module?

    If you look here (bottom left of the page) the KDE documentations instruct that in order to use a KDE Framework with QMake you have to add QT += KSyntaxHighlighting.

    And more important, does KDE install the module(s) where Qt looks for modules?

    Well this is the problem, Qt doesn't seem to be aware of the modules and I am not sure how to fix that.
    I will try to suggest your suggestion, in order to build I followed this guide



  • Hi @daljit97, as you guessed, the difficulty is in helping Qt to find the appropriate metadata so that qmake knows how to handle "KSyntaxHighlighting" when it finds it in your QMake project file.

    Looking at some of the Qt docs on a related topic, I found this page on advanced QMake usage.

    The part you care about is the third option to add features to qmake: using the QMAKEPATH environment variable. By exporting this variable in your shell to the KF5 install directory, qmake should be able to find the various KF5 modules.

    For example, my KF5 install is at ~/kde-5, so I did something like:

    export QMAKEPATH=$HOME/kde-5
    qmake
    make
    

    on a shell project

    # program.pro
    TEMPLATE = app
    TARGET = program
    INCLUDEPATH += .
    QT += widgets KSyntaxHighlighting
    SOURCES += main.cpp
    
    // main.cpp
    #include <QMainWindow>
    #include <QApplication>
    #include <QLabel>
    #include <Definition>
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
    
        QMainWindow *win = new QMainWindow;
        KSyntaxHighlighting::Definition def;
    
        win->setCentralWidget(
                new QLabel(QStringLiteral("Hi!"), win)
                );
        win->show();
    
        return app.exec();
    }
    

    It is also possible to build Qt applications with CMake, and that is more traditional for significant KF5 users. But as long as this works for you it looks like it won't be too hard to do what you're trying to do while continuing to use qmake.


  • Qt Champions 2018

    @daljit97

    I'm not sure about the KDE frameworks, but for Qt modules there is a make install step that copies headers and libraries to the Qt installation, overwriting existing files if needed.

    On Linux, this will probably require root permissions, but afterwards the additional libs are part of your Qt installation and should work like every other Qt module.

    Regards



  • @mpyne said in How to use KDE Frameworks with Qt Creator:

    Hi @daljit97, as you guessed, the difficulty is in helping Qt to find the appropriate metadata so that qmake knows how to handle "KSyntaxHighlighting" when it finds it in your QMake project file.

    Looking at some of the Qt docs on a related topic, I found this page on advanced QMake usage.

    The part you care about is the third option to add features to qmake: using the QMAKEPATH environment variable. By exporting this variable in your shell to the KF5 install directory, qmake should be able to find the various KF5 modules.

    For example, my KF5 install is at ~/kde-5, so I did something like:

    export QMAKEPATH=$HOME/kde-5
    qmake
    make
    

    on a shell project

    # program.pro
    TEMPLATE = app
    TARGET = program
    INCLUDEPATH += .
    QT += widgets KSyntaxHighlighting
    SOURCES += main.cpp
    
    // main.cpp
    #include <QMainWindow>
    #include <QApplication>
    #include <QLabel>
    #include <Definition>
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
    
        QMainWindow *win = new QMainWindow;
        KSyntaxHighlighting::Definition def;
    
        win->setCentralWidget(
                new QLabel(QStringLiteral("Hi!"), win)
                );
        win->show();
    
        return app.exec();
    }
    

    It is also possible to build Qt applications with CMake, and that is more traditional for significant KF5 users. But as long as this works for you it looks like it won't be too hard to do what you're trying to do while continuing to use qmake.

    Ok so that was very helpful. On my machine that KSyntaxHighlighting had a .pri file in /usr/lib/x86_64-linux-gnu/qt5/mkspecs/modules. Following your suggestion I added a QMAKEPATH Environment variable in Qt Creator using the GUI tool that Qt Creator provides and now everything works!
    0_1562930894756_Screenshot from 2019-07-12 12-27-19.png