2

I have yocto dev environment setup, in which I can bitbake and run a simple c++ application in the target. Now I want to try with simple Qt application. When I execute bitbake-layers show-layers it shows meta-qt5 in the list...

meta-qt5
/home/prc1cob/repo/out/salt/kawa/../../..//os/external/meta-qt5 7 meta-oe
/home/prc1cob/repo/out/salt/kawa/../../../build/yocto/meta-openembedded/meta-oe 6

With this, I assume qt5 is already present in my yocto build. How to write .bb file to build a simple HelloWorld qt application as below...

#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    
    qDebug() << "Hello World";

    return a.exec();
}

Thankyou!!

1 Answer 1

6

Yocto provides a great class qmake5 to compile QT projects based on QMake.

In order to use it create a .pro file for the project:

qtexample.pro

QT += core
SOURCES += qtexample.cpp

qtexample.cpp

#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    
    qDebug() << "Hello World";

    return a.exec();
}

Now, in your layer, you can add a simple recipe that compiles that project.

For example: meta-custom/recipes-project/qtexample

In qtexample folder create files folder and copy qtexample.pro and qtexample.cpp in it.

In qtexample folder directly create qtexample_0.1.bb recipe:

SUMMARY = "QT Example Recipe"
LICENSE = "CLOSED"

SRC_URI = "file://qtexample.pro \
           file://qtexample.cpp"

DEPENDS += "qtbase"
RDEPENDS_${PN} += "qtwayland"

S = "${WORKDIR}"

inherit qmake5

You can change the version ofcourse (0.1).

The layout should look like this:

meta-custom/
    ├── recipes-project/
        ├── qtexample_0.1.bb
        └── files/
            ├── qtexample.pro
            └── qtexample.cpp

Then, bitbake qtexample should work and create a qtexample binary that you can find in ${WORKDIR}

Sign up to request clarification or add additional context in comments.

3 Comments

@TALEL Thanks for the Great explanation. When I try to run bitbake got error as "ERROR: Nothing PROVIDES 'libnfc'", then removed libnfc in .bb file. now I am getting below errors in log.do_configure .. .../qtbase/5.12.3+gitAUTOINC+b527725766-r0/git/config.tests/x86_simd/main.cpp > arm-poky-linux-gnueabi-g++: error: unrecognized command line option '-mrdrnd' > Makefile:176: recipe for target 'main.o' failed > make: *** [main.o] Error 1
Sorry, the libnfc and libmodbus were my mistake, so I removed them. I didn't understand the error, I think it is not related to the qt application. Please update your question and provide the error there in a more clear way.
I am not sure its related to Qt or not, but this error is thrown when qtbase is getting build : arm-poky-linux-gnueabi-g++: error: unrecognized command line option '-mrdrnd' and from the log file the path for the error is shown as tmp/work/armv7at2hf-neon-poky-linux-gnueabi/qtbase/5.12.3+gitAUTOINC+b527725766-r0/git/config.tests/x86_simd/main.cpp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.