Qt Creator Debug works but release cannot be compiled - qt

I have some trouble to generate a release folder in QtCreator 4.7.2 based on Qt 5.11.2 (MSVC 2015, 32 bit). My program runs just fine in the debug version, but when I change the build to the release version, I get compiler errors.
I use the QCustomPlot library inside my application, and somehow in the release build it does not like
integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")
which throws me a C2446: ':': no conversion from 'QLatin1String' to 'QStringBuilder'
So I replaced the line for testing with
integerPart > 0 ? "" : ""
and so the compiler throws no more errors, but now I get a LNK1158: cannot run 'rc.exe'
I tried to clean the build and run qmake, but the linker error does not disappear. Any Ideas what could cause this problems? I only switched from debug to release.
Edit:
#-------------------------------------------------
#
# Project created by QtCreator 2018-11-09T09:59:59
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
TARGET = PlotterApp
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_USE_QSTRINGBUILDER
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
QT += serialport
SOURCES += \
main.cpp \
mainwindow.cpp \
serialporthandler.cpp \
qcustomplot.cpp \
parameterobject.cpp
HEADERS += \
mainwindow.h \
serialporthandler.h \
qcustomplot.h \
parameterobject.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

Go to this folder
C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86
and copy rc.exe and rcdll.dll to the following folder
X64
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64
X86
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin

Related

SerialPort module in Qt creator

I am creating a GUI app with Qt creator to communicate with an esp32 and control the outputs. I am currently using Qt 6.4 version, I know lib is not available in 6.0 or 6.1 but I couldn't find anything on 6.4.
This pages advices to input QT += serial port; https://doc.qt.io/qt-6/qtserialport-index.html. In my Qt app my.pro file I declare this:
QT += core gui serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = serialRead
TEMPLATE = app
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Error Message:
:-1: error: Project ERROR: Unknown module(s) in QT: serialport
I still dont know what to do to be able to use the QSerialPort library. I would appreciate any guidance. Thank you!
I solved the same issue with https://wiki.qt.io/Qt_Serial_Port
Install Perl (i.e Strawberry Perl)
Clone the qtserialport repo
git clone git://code.qt.io/qt/qtserialport.git
cd qtserialport
Checkout to suitable branch (you can list present branches with "git branch -a")
git checkout remotes/origin/6.3.1
Open qtserialport project with Qt Creator via CMakeLists.txt
In the "Projects" tab find "Build Steps" group, expand "Details" and check "install"
Rebuild the project from menu "Build->Rebuild"
It would be installed automatically. You may check it in the "Compile output". Note, that you have to rebuild the project for each build configuration you need.
Hope it will helps.
Use the application QT Maintenance Tool to add serialport lib.

Qt Creator isn't parsing include files properly and displays lots of errors

Qt Creator is not parsing the include files in my project properly and gives a lot of errors in the IDE, including errors like main.cpp:14:5: error: unknown type name 'QApplication'. However, my project compiles perfectly fine. I am getting tired of all these supposed errors and am wondering if there is any way to fix this issue.
My .pro file looks like this:
QT += core gui widgets
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
klocktimer.cpp \
main.cpp \
klockmainwindow.cpp \
chronometer.cpp
TRANSLATIONS += \
klock_en_US.ts \
klock_es_MX.ts
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
klocktimer.h \
klockmainwindow.h \
chronometer.h
I had a hunch from a few days ago (I forget exactly how I got this hunch) that stddef.h was causing the problem. So I added #include <stddef.h> to my main.cpp, and Qt Creator gave the error:
/home/loren/code/klock/main.cpp:12: error: 'stddef.h' file not found
/usr/include/c++/9/ostream:42: to match this '{'
where the '{' is the beginning { in namespace std.
Somebody on the Qt forums told me to go to the Help Menu > About Plugins > Disable the ClangCodeModel plugin. This required a restart of Qt Creator, but it fixed my problem.

Qt Deployment error 0xc0000007b on Windows

I have a Qt 5.12 Windows app. I'm using Qt Creator and Mingw 64 bit.
I've deployed the app by windeployqt.exe. When I start it, the app requires the libgcc_s_seh-1.dll file. After I paste it in the dir, I get the 0xc000007b error. I ran Dependency Walker and it gives me the following errors:
Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Error: A circular dependency was detected.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
This is my .pro file
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Control
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QMAKE_LFLAGS += -static-libgcc
##CONFIG += c++11
##QMAKE_CXXFLAGS += -std=c++0x
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
Can someone help me? Thank you very much.
I had a similar problem in the past, but I am not pretty sure if it's the same reason because I was compiling with MVSC.
In my case, the application internally links with x86 dependency files. I did download and install x64 dependency files and link with x64 files.
Anyway, the old version of Dependency Walker doesn't know to skip 32-bit DLLs in PATH when processing a 64-bit EXE or DLL the way Windows does, so some errors are not really relevant. You may find more information in this post.
If the problem remains, try to avoid the usage of a static version of libgcc, acording to this post. It is not designed to be statically linked.
...
#QMAKE_LFLAGS += -static-libgcc
...
I got that error when the compiled app could not see the Qt dlls, so check your path. It could also be that it cannot find other gcc dll, like libwinpthread-1.dll.

qmake no bluetooth

I Have a project that uses QT Bluetooth and i managed to compile it up until today
Today when calling QMake I get
Project MESSAGE: Warning: unknown QT: bluetooth
the .pro file looks something like this:
######################################################################
# Automatically generated by qmake (3.0) Thu Sep 29 10:34:51 2016
######################################################################
QT += bluetooth
QT += core
QT -= gui
CONFIG += c++11
CONFIG += debug
TEMPLATE = app
TARGET = build/ankioverdrive
#INCLUDEPATH += .
LIBS += -lmosquittopp
LIBS += -L/usr/lib
INCLUDEPATH += /usr/include/
# Input
SOURCES += some/paths/to/files.cpp \
HEADERS += \
some/paths/to/files.h \
running qmake --version which seemd to be the problem for some before gave me
QMake version 3.1
Using Qt version 5.9.5 in /usr/lib/x86_64-linux-gnu
I'm on Kubuntu 18.04
I fixed the Problem by reinstalling Qt via the qt-unified install tool for linux, and running the qmake file in that installPath
PathToInstallation/version/gcc_64/bin/qmake
this worked

Qt Creator release mode undefined references to std::out_of_range

I'm writing a small C++ program (with a GUI) with Qt Creator and compiling with MinGW. Everything works fine when I compile the project in debug mode but as soon as I move to release mode I get compiler errors:
undefined reference to 'std::out_of_range::~out_of_range()' thread.cpp
When I click on the error I also get:
File not found: thread.cpp
I have looked through my Boost installation and found thread.cpp and it should be on the include path for my project.
Any ideas?
EDIT: Here is my .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2012-08-10T12:09:39
#
#-------------------------------------------------
QT += core gui
TARGET = GeneDropWin
TEMPLATE = app
SOURCES += main.cpp \
genedrop.cpp \
mainbody.cpp \
biofunctions.cpp \
fileio.cpp \
settings.cpp
HEADERS += genedrop.h \
geneclasses.h \
paramclass.h \
mainbody.h \
biofunctions.h \
fileio.h \
geneclasses.h \
settings.h
FORMS += genedrop.ui \
settings.ui
#Stuff I've added
INCLUDEPATH += "C:\\Program Files\\boost_1_50_0"
LIBS += -L"C:\\Program Files\\boost_1_50_0\\stage\\lib" -lboost_thread-mgw46-mt-1_50 -lboost_system-mgw46-mt-1_50 -lboost_date_time-mgw46-mt-1_50 -lboost_chrono-mgw46-mt-1_50
CONFIG += static \
release
RESOURCES += \
NIABLogo.qrc
Ok, the problem is fixed but perhaps not completely understood. I fixed it by switching compiler to MSVC and changing the syntax for the linker options (e.g. -lboost_thread-mgw46-mt-1_50 -> -llibboost_thread-vc100-mt-1_50), compiles without an issue now. I will put forward my reasoning as to what I think may have been the problem but would appreciate a better answer if wrong:
Although I thought I had built the Boost libraries with MinGW when looking through the installation I found a number of folders mentioning msvc instead (e.g. ...boost\bin.v2\libs\date_time\build_msvc-10.0) which suggested to me that I had built it with MSVC.
The linker error claimed not to be able to find files associated with thread.cpp.
Looking at the thread folder of the build directory all the .obj and .lib files had msvc-10.0 folders in their path.
Thus I think that the MinGW compiler was looking for boost objects within a non-existent MinGW folder and so was failing. The fact that it worked under debug mode I guess relates to a less-constrained search for files.

Resources