Build Qt4 project with Serialport support using CMake - qt

I'm trying to build Qt4 (version 4.8.6) project with Serialport support using CMake (version 2.8.12). Here is the line that adds Qt4 support from my CMake:
find_package (Qt4 COMPONENTS QTCore QTGui REQUIRED)
include("${QT_USE_FILE}")
add_executable(myapp ${SOURCES})
target_link_libraries(myapp ${QT_LIBRARIES})
and getting the following error:
fatal error: QSerialPort: No such file or directory #include <QSerialPort>
I understand that FindQt4.cmake module doesn't have Serialport since it was introduced in Qt5 so i built Serialport library from sources. So the question is how to include the Qt library that is absent in FindQt4.cmake module to build the project via CMake.

The serial port module's code should be a part of your project. Since the project depends on Qt 4, lacking that module, you must bring the code with you. It just a couple of files, adding them to your project is trivial.

Related

Detect static Qt in cmake

How can I detect if the used version of Qt is statically built in a cmake project?
My goal is to make my project files independent from the version of Qt that is used to build it, and there are a few places where I need to differ between dynamic and static builds.
It works like for every other library in cmake, see here:
find_package(Qt5 COMPONENTS Core REQUIRED)
get_target_property(MY_QT_TARGET_TYPE Qt5::Core TYPE)
if(MY_QT_TARGET_TYPE STREQUAL STATIC_LIBRARY)
message("Qt was built as a static library!")
endif()

Unknown module(s) in QT: 3dstudioruntime2

I installed qt creator and qt 3dstudio with the qtOnline installer for linux. I want to build a project using these two packages. I design my project in qt3dstudio and then I use qtcreator to code the logic of the program. But I cannot import qt3dstudio module into the code.any suggestions??
I need to get this going on ubuntu 16.04LTS. I couldn't find anything useful on the web about the problem. I did try to build qt3dstudio but some of the dependencies caused my ubuntu desktop to stop working and I had to reinstall ubuntu.
QT modules in my .pro file:
QT += widgets qml quick gui 3dstudioruntime2
and when I hit build I get the following error:
Unknown module(s) in QT: 3dstudioruntime2

QtCreator 4.4.1 MINGW and Qt 5.9.1 Can not debug Qt sources

I recently am struggling by trying to debug Qt sources with my MINGW,QtCreator,Qt installation.
I did create a sample app, deployed it with the windeployqt tool and let it execute but when I am trying to debug, let s say step into one of the fancy Qt classes and methods I did obtain assembly code. I am plagued by assemply code also when trying to step over the
QApplication a(argc, argv);
I did build Qt from sources so the sources should not be a problem, I did not move the sources nor removed them.
When I used the objdump tool against qt libraries (debug version) to understand where the sources had to be I discovered that the libs were pointing to the correct source location.
I did also tried to play with the qtcreator qt source mappings but I did lost only a whole day by trying to understand what the heck those mappings do expect and either this try did not get me nothing.
In short, I have qt sources where they should be but gdb is for some reason not getting it.
This is my CMakelists.txt make file which one am importing in QtCreator:
cmake_minimum_required (VERSION 2.6)
project(sampleapp2)
#set(DEPS -lglu32 -lopengl32 -lgdi32 -luser32)
set(QT_DEPS "")
find_package(Qt5Widgets)
if(Qt5Widgets_FOUND)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
set(QT_DEPS ${QT_DEPS} ${Qt5Widgets_LIBRARIES})
endif()
find_package(Qt5Core)
if(Qt5Core_FOUND)
include_directories(${Qt5Core_INCLUDE_DIRS})
set(QT_DEPS ${QT_DEPS} ${Qt5Core_LIBRARIES})
endif()
find_package(Qt5Gui)
if(Qt5Gui_FOUND)
include_directories(${Qt5Gui_INCLUDE_DIRS})
set(QT_DEPS ${QT_DEPS} ${Qt5Gui_LIBRARIES})
endif()
#print qt deps (if any has been found), if not do exit
if(QT_DEPS)
message(STATUS "Qt dependencies are: " ${QT_DEPS})
else()
message(STATUS "Qt dependencies not found, exiting...")
exit()
endif()
#set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CXXFLAGS -g)
set(QMAKE_CXXFLAGS -g)
set(GUI_TYPE WIN32)
set(LIB_SOURCES maindialog.cpp)
set(EXE_SOURCES main.cpp)
set(UI_LIB sampleapp2ui)
QT5_WRAP_CPP(sampleapp2ui_hdr_moc maindialog.h)
QT5_WRAP_UI(sampleapp2ui_form_hdr maindialog.ui)
set(LIB_SOURCES ${LIB_SOURCES} ${sampleapp2ui_hdr_moc} ${sampleapp2ui_form_hdr})
add_library(${UI_LIB} SHARED ${LIB_SOURCES})
#qt5_use_modules(${UI_LIB} Core Gui Widgets)
target_link_libraries(${UI_LIB} ${QT_DEPS})
add_executable(sampleapp2 ${GUI_TYPE} ${EXE_SOURCES})
target_link_libraries(sampleapp2 ${UI_LIB} ${QT_DEPS})
#target_link_libraries(sampleapp2 ${UI_LIB})
#qt5_use_modules(sampleapp2 Core Gui Widgets)
Another wired thing is that I completely can not jump in the maindialog.cpp definitions which is something I should be able to - the maindialog.cpp is not part of any qt library - it is my own main dialog wrapped around the qt resources that I am using to specialize it.
Thank you in advice!

QT project port to QT5.7

I get an QT project that uses cmake not qmake. CMakeList.txt file includes some QT modules.
find_package (Qt5 REQUIRED COMPONENTS Widgets Core Gui Multimedia SerialPort Declarative)
I run QT5.7 using sudo ./qt-unified-xxxx.run command. It tried to install /opt/ folder, I didn't change this path.
If I write Qml Quick module instead of Declarative, I get c++11 error.
/QtCore/qbasicatomic.h:61:4: error: #error "Qt requires C++11 support"
# error "Qt requires C++11 support"
After installation, I arrange project setting to use cmake. But qt run button is not active due to below message.
Project ERROR: Unknown module(s) in QT: declarative
I check QT5 submodules, QT5.7 does not include Declarative module.When
I could not find how to install Declarative module or handle this problem.
Ok, I see that Declarative was removed only starting from Qt 5.6 (https://wiki.qt.io/New_Features_in_Qt_5.6). Replace it with QtQuick and fix all QML/C++ code if there are errors (http://doc.qt.io/qt-5/qtquick-porting-qt5.html).

Qt Creator 3 for windows - KDiff build error

I'm getting the following error message when building a project (KDiff3) in Qt Creator for Windows, any help would be appreciated.
C:\kdiff3\src-QT4\kreplacements\kreplacements.h:27:
error: QMainWindow: No such file or directory
#include < QMainWindow>
When updating a QT project from QT4 to QT5 if you see the above error, you will need to edit your .pro file to include:
QT += widgets
Transition from Qt 4.x to Qt5

Resources