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.
  • Ash VA Offline
    Ash VA Offline
    Ash V
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • Ash VA Ash V

      @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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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.

      Ash VA 1 Reply Last reply
      2
      • JonBJ JonB

        @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.

        Ash VA Offline
        Ash VA Offline
        Ash V
        wrote on 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.

        Axel SpoerlA 1 Reply Last reply
        0
        • Ash VA Ash V

          @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.

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on 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

          Ash VA 1 Reply Last reply
          1
          • Axel SpoerlA Axel Spoerl

            @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)
            
            Ash VA Offline
            Ash VA Offline
            Ash V
            wrote on last edited by
            #5

            @Axel-Spoerl
            Thanks Axel !

            Thank you very much for your valuable reply !

            1 Reply Last reply
            1
            • JonBJ JonB referenced this topic on
            • JonBJ JonB referenced this topic on

            • Login

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