Program crashes at the beginning of main() in debug mode, but runs through in Release mode
-
Qt Version: 6.5.3
QtCreator version: Qt Creator 14.0.1
Compiler setup:
After some testing to try and figure out what was causing it, I found that I could cause it to crash with just these lines:
int main(int argc, char *argv[]) { string test = "test"; QString test1 = QString::fromStdString(test); ...Where the debugger stops on the "test1" initialization with this stack trace:

I am completely baffled as to why it could crash this early in the program, and am at a loss as to where to look or what to try next. Any guidance as to what to investigate would be very much appreciated
-
Qt Version: 6.5.3
QtCreator version: Qt Creator 14.0.1
Compiler setup:
After some testing to try and figure out what was causing it, I found that I could cause it to crash with just these lines:
int main(int argc, char *argv[]) { string test = "test"; QString test1 = QString::fromStdString(test); ...Where the debugger stops on the "test1" initialization with this stack trace:

I am completely baffled as to why it could crash this early in the program, and am at a loss as to where to look or what to try next. Any guidance as to what to investigate would be very much appreciated
@MackS
Do not use any Qt classes/code until after you have instantiated whichever you want derived fromQCoreApplication, which should be about the first statement inmain().UPDATE
Apparently not forQString, I learn to my surprise. So this is not the issue. Doubtless @Christian-Ehrlicher's reply below is the correct answer. -
Don't mix debug and release libraries as you do (msvcrt release lib, Qt debug libs I would guess). How did you create your project? Please show the CMakeLists.txt.
-
How do you create your project / visual studio solution? Manually?
-
Using qmake <project>.pro:
qmake steps:
C:/Qt/6.5.3/msvc2019_64/bin/qmake.exe <project>.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug" && C:/Qt/Tools/QtCreator/bin/jom/jom.exe qmake_allMake steps:
jom.exe in C:<projectPath>\Desktop_Qt_6_5_3_MSVC2019_64bit-Debug -
Using qmake <project>.pro:
qmake steps:
C:/Qt/6.5.3/msvc2019_64/bin/qmake.exe <project>.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug" && C:/Qt/Tools/QtCreator/bin/jom/jom.exe qmake_allMake steps:
jom.exe in C:<projectPath>\Desktop_Qt_6_5_3_MSVC2019_64bit-Debug -
QT += quick QT += quickcontrols2 QT += core QT += network CONFIG += c++17 # The following define makes your compiler emit warnings if you use # any feature of Qt which as 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 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 SOURCES += \ sources.cpp ... HEADERS += \ headers.h ... RESOURCES += qml.qrc \ prodRes.qrc \ imagine-assets/imagine-assets.qrc #Share files INCLUDEPATH += $$PWD/../share $$PWD/../lib/gtest/include release{ LIBS += -L$$PWD/../lib/gtest/msvc/x64/release } debug{ LIBS += -L$$PWD/../lib/gtest/msvc/x64/debug } LIBS += -lQt6Core -lQt6Gui -lQt6Quick -lQt6QuickControls2 LIBS += -L"C:\\Qt\\6.5.3\\msvc2019_64\\lib" *msvc*: QMAKE_CXXFLAGS += /std:c++17 /DWINDOWS=1 /DNOFILELOCKING=1 #*msvc*: QMAKE_LFLAGS += /DEBUG:FULL *wasm*: QMAKE_CXXFLAGS += -std=c++17 -Wc++17-extensions -DNOFILELOCKING=1 -DZIP_STD -DUNIX -mnontrapping-fptoint *wasm*: QMAKE_LFLAGS += -s \"BINARYEN_TRAP_MODE=\'clamp\'\" #*wasm*: QMAKE_LFLAGS += -s \"BINARYEN_TRAP_MODE=\'clamp\'\" -s LEGACY_VM_SUPPORT=1 -s WASM=0 #QMAKE_CXXFLAGS += -showIncludes #load(moc) #QMAKE_MOC += -DQTMOCBUILD=1 SOURCES += \ otherSources... HEADERS += \ otherHeaders... # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = #Enable TLS/SSL EXTRA_QT_PLUGINS=tls CONFIG += ssl TARGET = trgt # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target FORMS += DESTDIR = ../run #RC_FILE = prod.rc RC_ICONS = prod.ico VERSION = vers QMAKE_TARGET_COMPANY = comp QMAKE_TARGET_PRODUCT = prod QMAKE_TARGET_DESCRIPTION = desc QMAKE_TARGET_COPYRIGHT = cr DISTFILES += \ config.cfg # copy all the files in the config dir to the destination dir... copyconfig.commands = $(COPY_DIR) $$shell_path($$PWD/config) $$shell_path($$DESTDIR) first.depends = $(first) copyconfig export(first.depends) export(copyconfig.commands) QMAKE_EXTRA_TARGETS += first copyconfig
I took the liberty to wrap the file content in code tags, in future please use the provided button to place code fragments in the appropriated code block or manually wrap it using ```
@J.Hilk -
QT += quick QT += quickcontrols2 QT += core QT += network CONFIG += c++17 # The following define makes your compiler emit warnings if you use # any feature of Qt which as 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 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 SOURCES += \ sources.cpp ... HEADERS += \ headers.h ... RESOURCES += qml.qrc \ prodRes.qrc \ imagine-assets/imagine-assets.qrc #Share files INCLUDEPATH += $$PWD/../share $$PWD/../lib/gtest/include release{ LIBS += -L$$PWD/../lib/gtest/msvc/x64/release } debug{ LIBS += -L$$PWD/../lib/gtest/msvc/x64/debug } LIBS += -lQt6Core -lQt6Gui -lQt6Quick -lQt6QuickControls2 LIBS += -L"C:\\Qt\\6.5.3\\msvc2019_64\\lib" *msvc*: QMAKE_CXXFLAGS += /std:c++17 /DWINDOWS=1 /DNOFILELOCKING=1 #*msvc*: QMAKE_LFLAGS += /DEBUG:FULL *wasm*: QMAKE_CXXFLAGS += -std=c++17 -Wc++17-extensions -DNOFILELOCKING=1 -DZIP_STD -DUNIX -mnontrapping-fptoint *wasm*: QMAKE_LFLAGS += -s \"BINARYEN_TRAP_MODE=\'clamp\'\" #*wasm*: QMAKE_LFLAGS += -s \"BINARYEN_TRAP_MODE=\'clamp\'\" -s LEGACY_VM_SUPPORT=1 -s WASM=0 #QMAKE_CXXFLAGS += -showIncludes #load(moc) #QMAKE_MOC += -DQTMOCBUILD=1 SOURCES += \ otherSources... HEADERS += \ otherHeaders... # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = #Enable TLS/SSL EXTRA_QT_PLUGINS=tls CONFIG += ssl TARGET = trgt # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target FORMS += DESTDIR = ../run #RC_FILE = prod.rc RC_ICONS = prod.ico VERSION = vers QMAKE_TARGET_COMPANY = comp QMAKE_TARGET_PRODUCT = prod QMAKE_TARGET_DESCRIPTION = desc QMAKE_TARGET_COPYRIGHT = cr DISTFILES += \ config.cfg # copy all the files in the config dir to the destination dir... copyconfig.commands = $(COPY_DIR) $$shell_path($$PWD/config) $$shell_path($$DESTDIR) first.depends = $(first) copyconfig export(first.depends) export(copyconfig.commands) QMAKE_EXTRA_TARGETS += first copyconfig
I took the liberty to wrap the file content in code tags, in future please use the provided button to place code fragments in the appropriated code block or manually wrap it using ```
@J.Hilk@MackS said in Program crashes at the beginning of main() in debug mode, but runs through in Release mode:
LIBS += -lQt6Core -lQt6Gui -lQt6Quick -lQt6QuickControls2
Why? This is not needed (QT += does what is needed to link Qt modules). This way you tell QMake to link release versions of these libs even in debug builds.
-
@MackS
Do not use any Qt classes/code until after you have instantiated whichever you want derived fromQCoreApplication, which should be about the first statement inmain().UPDATE
Apparently not forQString, I learn to my surprise. So this is not the issue. Doubtless @Christian-Ehrlicher's reply below is the correct answer.