QSignalSpy crashed the test executable when testing a static lib.
-
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.
-
Thank 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.
-
@Christian-Ehrlicher
The situation is turning strange because MinGW compiler works well with all styles, static or not. -
Then you somehow mix debug and release libraries which is not supported with MSVC.
-
@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