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. error connecting signal to slot in custom class

error connecting signal to slot in custom class

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 614 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.
  • D Offline
    D Offline
    Deneguil
    wrote on last edited by
    #1

    Hello, I am trying to connect a signal between a series in a custom chart class to a slot in said chart class like so:

    connect(series, SIGNAL(clicked(QPointF)), chart4Map, SLOT(pointClicked(QPointF)));
    

    mapChart

    class mapChart : public QChart
    {
    public slots:
        void pointClicked(const QPointF &point);
    };
    

    However when I do so I get the error QObject::connect: No such slot QtCharts::QChart::pointClicked(QPointF) which I don't understand as my chart4Map is a mapChart instance

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • D Deneguil

      Hello, I am trying to connect a signal between a series in a custom chart class to a slot in said chart class like so:

      connect(series, SIGNAL(clicked(QPointF)), chart4Map, SLOT(pointClicked(QPointF)));
      

      mapChart

      class mapChart : public QChart
      {
      public slots:
          void pointClicked(const QPointF &point);
      };
      

      However when I do so I get the error QObject::connect: No such slot QtCharts::QChart::pointClicked(QPointF) which I don't understand as my chart4Map is a mapChart instance

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Deneguil
      Since your slot signature parameter is const QPointF &point it won't match the plain QPointF in your SLOT().

      Why don't you use "new" (actually very old now!) signal/slot syntax, instead of SIGNAL/SLOT(), it gives more help on these errors?

      D 1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        The mapChart class presented is lacking a Q_OBJECT macro.
        Also, have you ensured that moc has run over the header declaring mapChart?

        JonBJ 1 Reply Last reply
        1
        • D Deneguil

          Hello, I am trying to connect a signal between a series in a custom chart class to a slot in said chart class like so:

          connect(series, SIGNAL(clicked(QPointF)), chart4Map, SLOT(pointClicked(QPointF)));
          

          mapChart

          class mapChart : public QChart
          {
          public slots:
              void pointClicked(const QPointF &point);
          };
          

          However when I do so I get the error QObject::connect: No such slot QtCharts::QChart::pointClicked(QPointF) which I don't understand as my chart4Map is a mapChart instance

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Deneguil you're using old(Qt4) signal slot syntax, so your class 100% requires Q_OBJECT macro to work.

          It is missing.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • C ChrisW67

            The mapChart class presented is lacking a Q_OBJECT macro.
            Also, have you ensured that moc has run over the header declaring mapChart?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @ChrisW67 said in error connecting signal to slot in custom class:

            The mapChart class presented is lacking a Q_OBJECT macro.

            This is true, but as far as I know Q_OBJECT is not required for slots, only for signals?

            Am I not right that the QPointF will not match const QPointF &point, and that is the error here? [UPDATE Oh, @J-Hilk says Qt4 will match these similar-but-different signatures, so maybe I am wrong, and it is indeed somehow the Q_OBJECT missing for Qt4, sorry if my attempts at answering have been wrong, I have learned something about Qt4 now! See also https://forum.qt.io/topic/115188/do-i-need-to-use-the-q_object-macro-if-i-only-use-slots]

            @J-Hilk said in error connecting signal to slot in custom class:

            @Deneguil you're using old(Qt4) signal slot syntax, so your class 100% requires Q_OBJECT macro to work.

            Ah, I did not know that requirement! I don't think it's mandatory for a slot in new style, at least? One more reason for using new-style if not bound to Qt4!

            J.HilkJ 1 Reply Last reply
            0
            • JonBJ JonB

              @ChrisW67 said in error connecting signal to slot in custom class:

              The mapChart class presented is lacking a Q_OBJECT macro.

              This is true, but as far as I know Q_OBJECT is not required for slots, only for signals?

              Am I not right that the QPointF will not match const QPointF &point, and that is the error here? [UPDATE Oh, @J-Hilk says Qt4 will match these similar-but-different signatures, so maybe I am wrong, and it is indeed somehow the Q_OBJECT missing for Qt4, sorry if my attempts at answering have been wrong, I have learned something about Qt4 now! See also https://forum.qt.io/topic/115188/do-i-need-to-use-the-q_object-macro-if-i-only-use-slots]

              @J-Hilk said in error connecting signal to slot in custom class:

              @Deneguil you're using old(Qt4) signal slot syntax, so your class 100% requires Q_OBJECT macro to work.

              Ah, I did not know that requirement! I don't think it's mandatory for a slot in new style, at least? One more reason for using new-style if not bound to Qt4!

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @JonB said in error connecting signal to slot in custom class:

              I don't think it's mandatory for a slot in new style, at least?

              you would be correct, the class containing the signal still requires it (I think)


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • JonBJ JonB

                @Deneguil
                Since your slot signature parameter is const QPointF &point it won't match the plain QPointF in your SLOT().

                Why don't you use "new" (actually very old now!) signal/slot syntax, instead of SIGNAL/SLOT(), it gives more help on these errors?

                D Offline
                D Offline
                Deneguil
                wrote on last edited by
                #7

                @JonB said in error connecting signal to slot in custom class:

                Since your slot signature parameter is const QPointF &point it won't match the plain QPointF in your SLOT().

                I tried fixing the slot signature and adding the Q_OBJECT macro to my class as well and this time I got QObject::connect: No such signal QtCharts::QScatterSeries::clicked(const QPointF &point) which seems weird to me since ScatterSeries should have the signal inhearited from XYSeries.

                Why don't you use "new" (actually very old now!) signal/slot syntax, instead of SIGNAL/SLOT(), it gives more help on these errors?

                There was no other reason than I'm pretty new to Qt development and so far that was the syntax that worked for me so I didn't see a reason to change.
                However after changing it to connect(series, &QScatterSeries::clicked, chart4Map, &mapChart::pointClicked); it works now so I'm probably going to change every SIGNAL()/SLOT() in my code now too

                Thank you all for your help

                JonBJ 1 Reply Last reply
                1
                • D Deneguil

                  @JonB said in error connecting signal to slot in custom class:

                  Since your slot signature parameter is const QPointF &point it won't match the plain QPointF in your SLOT().

                  I tried fixing the slot signature and adding the Q_OBJECT macro to my class as well and this time I got QObject::connect: No such signal QtCharts::QScatterSeries::clicked(const QPointF &point) which seems weird to me since ScatterSeries should have the signal inhearited from XYSeries.

                  Why don't you use "new" (actually very old now!) signal/slot syntax, instead of SIGNAL/SLOT(), it gives more help on these errors?

                  There was no other reason than I'm pretty new to Qt development and so far that was the syntax that worked for me so I didn't see a reason to change.
                  However after changing it to connect(series, &QScatterSeries::clicked, chart4Map, &mapChart::pointClicked); it works now so I'm probably going to change every SIGNAL()/SLOT() in my code now too

                  Thank you all for your help

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Deneguil said in error connecting signal to slot in custom class:

                  However after changing it to connect(series, &QScatterSeries::clicked, chart4Map, &mapChart::pointClicked); it works now so I'm probably going to change every SIGNAL()/SLOT() in my code now too

                  :) :) New style was introduced years & years ago. I know some old examples still use SIGNAL/SLOT(), but assuming you are Qt5 onward you are really a lot better off with new style!

                  1 Reply Last reply
                  0

                  • Login

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