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 using a QSharedPointer signal?
Forum Update on Monday, May 27th 2025

QSignalSpy using a QSharedPointer signal?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 417 Views
  • 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
    Calicoder
    wrote on 16 Mar 2022, 21:23 last edited by
    #1

    Good day fellow QT coders, hope your code compiles well. I've been reading up on using QTtest and how unit testing works overall. Been a fun last 2 days. I've noticed that QSIgnalSpy doesn't like when I use QSharedPointers to call the signal though.

    void UnitTest::checkSignal()
    {
    	QSharedPointer<ClassBegin> begin;
    	QSignalSpy beginSpy(&begin, &ClassBegin::update); <---- 
    }
    

    I keep getting a C++ a nonstatic member reference must be relative to a specific object error at the <---- line above. I didn't see it anywhere in the docs but can QSignalSPy use QSharedPointers?

    Appreciate the help, thank you!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Mar 2022, 21:57 last edited by
      #2

      Hi,

      You need to connect it to the object that is hold by the shared pointer not by the pointer.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply 16 Mar 2022, 22:04
      1
      • S SGaist
        16 Mar 2022, 21:57

        Hi,

        You need to connect it to the object that is hold by the shared pointer not by the pointer.

        C Offline
        C Offline
        Calicoder
        wrote on 16 Mar 2022, 22:04 last edited by
        #3

        @SGaist Thanks for the quick reply. So the code would look like this if I'm understanding your answer?

        void UnitTest::checkSignal()
        {
        	QSharedPointer<ClassBegin> begin;
        	QSignalSpy beginSpy(&begin, SIGNAL(&begin->update)); 
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Mar 2022, 22:18 last edited by
          #4

          No

          connect(begin.data(), ...)
          

          But you can only do this once you put something in the QSharedPointer so you might as well do a normal connect call when you set the object in "begin".

          You cannot "preemptlively" connect.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply 16 Mar 2022, 22:23
          1
          • S SGaist
            16 Mar 2022, 22:18

            No

            connect(begin.data(), ...)
            

            But you can only do this once you put something in the QSharedPointer so you might as well do a normal connect call when you set the object in "begin".

            You cannot "preemptlively" connect.

            C Offline
            C Offline
            Calicoder
            wrote on 16 Mar 2022, 22:23 last edited by
            #5

            @SGaist Ahhh ok that makes sense. Perfect, thanks so much

            1 Reply Last reply
            0

            1/5

            16 Mar 2022, 21:23

            • Login

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