Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSignalSpy crashed the test executable when testing a static lib.
Forum Updated to NodeBB v4.3 + New Features

QSignalSpy crashed the test executable when testing a static lib.

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 934 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CKurdu
    wrote on 11 Nov 2023, 08:58 last edited by
    #1

    While testing a static library, the test app crashed due to QSignalSpy.

    Project structure.
    5c63549d-07a7-4adf-b5ea-83abebf07c31-image.png

    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
    718d1d33-504d-4d0a-a7b6-2576c7da5e7d-image.png

    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?

    You reap what you sow it

    C 1 Reply Last reply 11 Nov 2023, 09:02
    0
    • C CKurdu
      11 Nov 2023, 08:58

      While testing a static library, the test app crashed due to QSignalSpy.

      Project structure.
      5c63549d-07a7-4adf-b5ea-83abebf07c31-image.png

      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
      718d1d33-504d-4d0a-a7b6-2576c7da5e7d-image.png

      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?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 11 Nov 2023, 09:02 last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 2 Replies Last reply 11 Nov 2023, 09:16
      0
      • C Christian Ehrlicher
        11 Nov 2023, 09:02

        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.

        C Offline
        C Offline
        CKurdu
        wrote on 11 Nov 2023, 09:16 last edited by
        #3

        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.

        You reap what you sow it

        1 Reply Last reply
        0
        • C Christian Ehrlicher
          11 Nov 2023, 09:02

          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.

          C Offline
          C Offline
          CKurdu
          wrote on 11 Nov 2023, 09:52 last edited by
          #4

          @Christian-Ehrlicher
          The situation is turning strange because MinGW compiler works well with all styles, static or not.

          You reap what you sow it

          C 1 Reply Last reply 11 Nov 2023, 10:01
          0
          • C CKurdu
            11 Nov 2023, 09:52

            @Christian-Ehrlicher
            The situation is turning strange because MinGW compiler works well with all styles, static or not.

            C Offline
            C Offline
            CKurdu
            wrote on 11 Nov 2023, 10:01 last edited by
            #5

            The problem only occurs in debug mode.
            99cfa7ed-d9da-4f51-8eaf-77b96a32021c-image.png

            When Qt Creator is in debug mode, the program crashes.

            OMG, I spent four hours on this.

            You reap what you sow it

            C 1 Reply Last reply 11 Nov 2023, 10:46
            0
            • C CKurdu
              11 Nov 2023, 10:01

              The problem only occurs in debug mode.
              99cfa7ed-d9da-4f51-8eaf-77b96a32021c-image.png

              When Qt Creator is in debug mode, the program crashes.

              OMG, I spent four hours on this.

              C Offline
              C Offline
              CKurdu
              wrote on 11 Nov 2023, 10:46 last edited by
              #6

              The problem occurs with below config

              Qt 6 6 0 MSVC2019 64bit debug.
              debug mode
              

              68b64a2c-7c5e-486c-aa26-4ec2af73eab3-image.png

              You reap what you sow it

              C 1 Reply Last reply 11 Nov 2023, 11:21
              0
              • C CKurdu
                11 Nov 2023, 10:46

                The problem occurs with below config

                Qt 6 6 0 MSVC2019 64bit debug.
                debug mode
                

                68b64a2c-7c5e-486c-aa26-4ec2af73eab3-image.png

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 11 Nov 2023, 11:21 last edited by
                #7

                Then you somehow mix debug and release libraries which is not supported with MSVC.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                C 1 Reply Last reply 12 Nov 2023, 11:16
                0
                • C Christian Ehrlicher
                  11 Nov 2023, 11:21

                  Then you somehow mix debug and release libraries which is not supported with MSVC.

                  C Offline
                  C Offline
                  CKurdu
                  wrote on 12 Nov 2023, 11:16 last edited by
                  #8

                  @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

                  You reap what you sow it

                  C 1 Reply Last reply 14 Nov 2023, 04:39
                  0
                  • C CKurdu
                    12 Nov 2023, 11:16

                    @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

                    C Offline
                    C Offline
                    CKurdu
                    wrote on 14 Nov 2023, 04:39 last edited by
                    #9

                    The 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

                    You reap what you sow it

                    1 Reply Last reply
                    0

                    1/9

                    11 Nov 2023, 08:58

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved