QML Conditional Based on Kit
-
I would like to specify a custom gstreamer pipeline for my MediaPlayer when running on embedded Linux (but not when running on desktop Linux). I can't use Qt.platform.os as this is "linux" for both. How can I detect the Kit (or any other parameter making it possible to detect the embedded Linux target) in QML?
-
I would like to specify a custom gstreamer pipeline for my MediaPlayer when running on embedded Linux (but not when running on desktop Linux). I can't use Qt.platform.os as this is "linux" for both. How can I detect the Kit (or any other parameter making it possible to detect the embedded Linux target) in QML?
-
@sierdzio Thanks! How would I do that? I'm currently trying to get a define added under the CMake configuration using something like
-DQMAKE_CXXFLAGS:STRING='-DEMBEDDED'
or
-DCMAKE_CXXFLAGS:STRING='-DEMBEDDED'
however I haven't been able to get this to work as yet. -
@sierdzio Thanks! How would I do that? I'm currently trying to get a define added under the CMake configuration using something like
-DQMAKE_CXXFLAGS:STRING='-DEMBEDDED'
or
-DCMAKE_CXXFLAGS:STRING='-DEMBEDDED'
however I haven't been able to get this to work as yet.@Dane-0 there are many ways to do it, personally I'd probably go with something like this:
In some CMakeLists.txt:
option(IS_EMBEDDED "Enable embedded mode" OFF) if (IS_EMBEDDED) message("Building embedded") add_definitions(-DEMBEDDED) endif()
You can call cmake with
cmake -DIS_EMBEDDED=ON
or just select that option in Qt Creator's Project->Build settings.Then, in C++ you can do this:
engine->rootContext()->setContextProperty("isEmbedded", #ifdef EMBEDDED true #else false #endif );
Lastly, in QML:
Text { text: isEmbedded ? "Embedded!" : "Desktop :-(" }
-
@sierdzio Thanks again! :-)
I am new to this so please excuse me if these questions are "silly":In some CMakeLists.txt:
There is not currently any CMakeLists.txt in the project. Must I add this manually? Or do I add something to the .pro file? What about under Kits -> CMake Configuration?
You can call cmake with cmake -DIS_EMBEDDED=ON or just select that option in Qt Creator's Project->Build settings.
Where would this option be selected? I'm looking under "Projects" (mode selected on the left), but don't immediately see "options" to be selected.
I follow with everything after that, just struggling to get the actual #define implemented.
-
@sierdzio Thanks again! :-)
I am new to this so please excuse me if these questions are "silly":In some CMakeLists.txt:
There is not currently any CMakeLists.txt in the project. Must I add this manually? Or do I add something to the .pro file? What about under Kits -> CMake Configuration?
You can call cmake with cmake -DIS_EMBEDDED=ON or just select that option in Qt Creator's Project->Build settings.
Where would this option be selected? I'm looking under "Projects" (mode selected on the left), but don't immediately see "options" to be selected.
I follow with everything after that, just struggling to get the actual #define implemented.
@Dane-0 said in QML Conditional Based on Kit:
@sierdzio Thanks again! :-)
I am new to this so please excuse me if these questions are "silly":In some CMakeLists.txt:
There is not currently any CMakeLists.txt in the project. Must I add this manually? Or do I add something to the .pro file? What about under Kits -> CMake Configuration?
If you have a .pro file then you are NOT using cmake but qmake.
So, with qmake this will be a bit different. In your .pro:
is-embedded { DEFINES += EMBEDDED }
Then call qmake with:
qmake CONFIG+=is-embedded
C++ and QML stay the same.