Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. expected primary expression before ',' token
QtWS25 Last Chance

expected primary expression before ',' token

Scheduled Pinned Locked Moved Unsolved Qt 6
5 Posts 3 Posters 822 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.
  • A Offline
    A Offline
    Ash V
    wrote on 29 Feb 2024, 10:47 last edited by
    #1

    @Axel-Spoerl
    Hello Axel !
    I hope this message finds you in good health and good spirits !

    Recently I was exploring the connect() method of the QObject class to connect signals-and-slots.

    But I'm getting this error:
    expected primary expression before ',' token.

    firstselfcodedqobjectclass.h
    ed940669-04c4-4ccd-b7ab-49291c0a586a-Screenshot from 2024-02-29 16-02-32.png
    firstselfcodedqobjectclass.cpp
    ba75e3ab-2997-4a87-895b-8cea72a48c14-Screenshot from 2024-02-29 16-01-01.png
    secondselfcodedqobjectclass.h
    4fef3bb7-e3d9-427f-a6b8-4819760e8054-Screenshot from 2024-02-29 16-01-41.png
    secondselfcodedqobjectclass.cpp
    --ERROR COMING IN THIS FILE--
    b5e043d3-8584-4876-8568-66951447fb66-Screenshot from 2024-02-29 16-00-42.png

    Would you please look into this issue and suggest me a viable solution to it.

    It would be a great help from your side Axel.

    J 1 Reply Last reply 29 Feb 2024, 10:59
    0
    • A Ash V
      29 Feb 2024, 10:47

      @Axel-Spoerl
      Hello Axel !
      I hope this message finds you in good health and good spirits !

      Recently I was exploring the connect() method of the QObject class to connect signals-and-slots.

      But I'm getting this error:
      expected primary expression before ',' token.

      firstselfcodedqobjectclass.h
      ed940669-04c4-4ccd-b7ab-49291c0a586a-Screenshot from 2024-02-29 16-02-32.png
      firstselfcodedqobjectclass.cpp
      ba75e3ab-2997-4a87-895b-8cea72a48c14-Screenshot from 2024-02-29 16-01-01.png
      secondselfcodedqobjectclass.h
      4fef3bb7-e3d9-427f-a6b8-4819760e8054-Screenshot from 2024-02-29 16-01-41.png
      secondselfcodedqobjectclass.cpp
      --ERROR COMING IN THIS FILE--
      b5e043d3-8584-4876-8568-66951447fb66-Screenshot from 2024-02-29 16-00-42.png

      Would you please look into this issue and suggest me a viable solution to it.

      It would be a great help from your side Axel.

      J Offline
      J Offline
      JonB
      wrote on 29 Feb 2024, 10:59 last edited by JonB
      #2

      @Ash-V
      Please paste code as text, not screenshot, so people can read/copy it.

      connect(FirstSetCodedObjectClass, ...): FirstSetCodedObjectClass is a class but connect() needs an instance for the signaller, just like the this you are using for the slot object. Signals & slots are connected between instances of signal/slot objects.

      You are trying to do connections in constructor of SecondSetCodedObjectClass. This is usually not good, because you would have to pass an instance of signalling object to that constructor. Rather the usual place to do the connect() is (on the line after) where you call new SecondSetCodedObjectClass, which has visibility of that new slot object and the existing signal object (FirstSetCodedObjectClass *) which you want to connect.

      A 1 Reply Last reply 29 Feb 2024, 11:10
      2
      • J JonB
        29 Feb 2024, 10:59

        @Ash-V
        Please paste code as text, not screenshot, so people can read/copy it.

        connect(FirstSetCodedObjectClass, ...): FirstSetCodedObjectClass is a class but connect() needs an instance for the signaller, just like the this you are using for the slot object. Signals & slots are connected between instances of signal/slot objects.

        You are trying to do connections in constructor of SecondSetCodedObjectClass. This is usually not good, because you would have to pass an instance of signalling object to that constructor. Rather the usual place to do the connect() is (on the line after) where you call new SecondSetCodedObjectClass, which has visibility of that new slot object and the existing signal object (FirstSetCodedObjectClass *) which you want to connect.

        A Offline
        A Offline
        Ash V
        wrote on 29 Feb 2024, 11:10 last edited by Ash V
        #3

        @JonB , @Axel-Spoerl
        Hello Jon !
        Thanks for your valuable reply.

        Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?

        I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above code that we can use it without necessarily having any Q_PROPERTY.

        This is the documentation I have referred to.

        A 1 Reply Last reply 29 Feb 2024, 12:28
        0
        • A Ash V
          29 Feb 2024, 11:10

          @JonB , @Axel-Spoerl
          Hello Jon !
          Thanks for your valuable reply.

          Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?

          I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above code that we can use it without necessarily having any Q_PROPERTY.

          This is the documentation I have referred to.

          A Offline
          A Offline
          Axel Spoerl
          Moderators
          wrote on 29 Feb 2024, 12:28 last edited by
          #4

          @Ash-V
          Q_PROPERTY macros are used to expose a property (at least a getter, possibly also a setter and a notification signal) to QML. You don't need it, if you do C++ only.

          Regarding the connect statement, @JonB has already nailed it.
          The constructor of SecondSelfCodedQObjectClassdoesn't know of any living instance of FirstSelfCodedQObjectClass. You have to create one, or pass it as an argument to the constructor.
          Assuming that FirstSelfCodedQObjectClass *first contains a valid pointer, the connect statement would be

          connect(first, &FirstSelfCodedQObjectClass::name1Changed,
                  this, &SecondSelfCodedQObjectClass::onName1Changed)
          

          Software Engineer
          The Qt Company, Oslo

          A 1 Reply Last reply 29 Feb 2024, 12:43
          1
          • A Axel Spoerl
            29 Feb 2024, 12:28

            @Ash-V
            Q_PROPERTY macros are used to expose a property (at least a getter, possibly also a setter and a notification signal) to QML. You don't need it, if you do C++ only.

            Regarding the connect statement, @JonB has already nailed it.
            The constructor of SecondSelfCodedQObjectClassdoesn't know of any living instance of FirstSelfCodedQObjectClass. You have to create one, or pass it as an argument to the constructor.
            Assuming that FirstSelfCodedQObjectClass *first contains a valid pointer, the connect statement would be

            connect(first, &FirstSelfCodedQObjectClass::name1Changed,
                    this, &SecondSelfCodedQObjectClass::onName1Changed)
            
            A Offline
            A Offline
            Ash V
            wrote on 29 Feb 2024, 12:43 last edited by
            #5

            @Axel-Spoerl
            Thanks Axel !

            Thank you very much for your valuable reply !

            1 Reply Last reply
            1
            • J JonB referenced this topic on 29 Feb 2024, 12:45
            • J JonB referenced this topic on 1 Mar 2024, 08:49

            1/5

            29 Feb 2024, 10:47

            • 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