QSignalSpy crashed the test executable when testing a static lib.
-
wrote on 11 Nov 2023, 08:58 last edited by
While testing a static library, the test app crashed due to QSignalSpy.
test CMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(testsubject LANGUAGES CXX) set(CMAKE_AUTOMOC ON) find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets) qt_add_executable(testsubject testsubject.cpp ) set_target_properties(testsubject PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(testsubject PUBLIC Qt::Core Qt::Gui Qt::Test Qt::Widgets subject )
testsubject.cpp
#include <QTest> #include "subject.h" #include <QSignalSpy> class TestSubject: public QObject { Q_OBJECT Subject* m_subject; private slots: void name(); void initTestCase() { m_subject = new Subject(); } }; void TestSubject::name() { QSignalSpy spy(m_subject,&Subject::nameChanged); m_subject->setName("cafer"); spy.wait(); QCOMPARE(spy.count(),1); } QTEST_MAIN(TestSubject) #include "testsubject.moc"
When I use subject source files without linking them statically adding directly, there are no problems.
The crash occurs when the spy object gets destroyed.
I'm unsure if this is a bug or I'm doing something incorrectly. Can you help me figure it out?
-
While testing a static library, the test app crashed due to QSignalSpy.
Project structure.
test CMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(testsubject LANGUAGES CXX) set(CMAKE_AUTOMOC ON) find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets) qt_add_executable(testsubject testsubject.cpp ) set_target_properties(testsubject PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(testsubject PUBLIC Qt::Core Qt::Gui Qt::Test Qt::Widgets subject )
testsubject.cpp
#include <QTest> #include "subject.h" #include <QSignalSpy> class TestSubject: public QObject { Q_OBJECT Subject* m_subject; private slots: void name(); void initTestCase() { m_subject = new Subject(); } }; void TestSubject::name() { QSignalSpy spy(m_subject,&Subject::nameChanged); m_subject->setName("cafer"); spy.wait(); QCOMPARE(spy.count(),1); } QTEST_MAIN(TestSubject) #include "testsubject.moc"
result
When I use subject source files without linking them statically adding directly, there are no problems.
The crash occurs when the spy object gets destroyed.
I'm unsure if this is a bug or I'm doing something incorrectly. Can you help me figure it out?
As always - use a debugger to see where it crashes. And then simplify the application until it either no longer crashes or you found the bug. If it's small enough, post a minimal, compilable reproducer here.
-
As always - use a debugger to see where it crashes. And then simplify the application until it either no longer crashes or you found the bug. If it's small enough, post a minimal, compilable reproducer here.
wrote on 11 Nov 2023, 09:16 last edited byThank you for your quick response @Christian-Ehrlicher
This is already a minimal example and below is a GitHub repository show that.
https://github.com/ckurdu/staticlib_qttest
It's interesting that the same problem started happening when I added subject files directly, so I think I am making a mistake this is not a bug.
-
As always - use a debugger to see where it crashes. And then simplify the application until it either no longer crashes or you found the bug. If it's small enough, post a minimal, compilable reproducer here.
wrote on 11 Nov 2023, 09:52 last edited by@Christian-Ehrlicher
The situation is turning strange because MinGW compiler works well with all styles, static or not. -
@Christian-Ehrlicher
The situation is turning strange because MinGW compiler works well with all styles, static or not.wrote on 11 Nov 2023, 10:01 last edited by -
The problem only occurs in debug mode.
When Qt Creator is in debug mode, the program crashes.
OMG, I spent four hours on this.
wrote on 11 Nov 2023, 10:46 last edited by -
Then you somehow mix debug and release libraries which is not supported with MSVC.
-
Then you somehow mix debug and release libraries which is not supported with MSVC.
wrote on 12 Nov 2023, 11:16 last edited by@Christian-Ehrlicher
I think you are right. Because, on my other PC, there is no problem. I tried many things.
I removed the debug folder to try to start the config cmake project from scratch. It didn't work. Now I am reinstalling Qt 6.6.0 -
@Christian-Ehrlicher
I think you are right. Because, on my other PC, there is no problem. I tried many things.
I removed the debug folder to try to start the config cmake project from scratch. It didn't work. Now I am reinstalling Qt 6.6.0wrote on 14 Nov 2023, 04:39 last edited byThe problem was solved after I reinstalled Qt 6.6.0. However, I am still unsure of what caused the issue in the first place.
Thank You @Christian-Ehrlicher
1/9