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. Debug output when calling QToolBar::addAction()
Forum Updated to NodeBB v4.3 + New Features

Debug output when calling QToolBar::addAction()

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 1.0k Views 2 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.
  • B Offline
    B Offline
    Bonnie
    wrote on last edited by
    #2

    because you didn't give it a slot, but a normal string...

    1 Reply Last reply
    4
    • PerdrixP Perdrix

      I'm getting a debug output message:

      QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed

      when I do:

          QToolBar t(&w);
          QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp");
          t.setOrientation(Qt::Vertical);
          t.addAction(dragRect, "", &editor, "dragButtonPressed");
      

      clearly Qt doesn't love me a lot, but why?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #3

      @Perdrix

      Is DEditStars a QObject? Do you have Q_OBJECT macro in this class? Is your function dragButtonPressed a slot?

      And dont put the function name in double quotes, like @Bonnie already said

      https://doc.qt.io/qt-5/qtoolbar.html#addAction-3


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      3
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #4

        Yes, yes and yes!

        #include <QObject>
        class DEditStars :
            public QObject
        {
            Q_OBJECT
        
        typedef QObject
                Inherited;
        
        public:
            DEditStars() :
                QObject()
            {
            };
        
            virtual ~DEditStars() {};
        
        public slots:
            void mousePressEvent(QMouseEvent* e);
            void mouseMoveEvent(QMouseEvent* e);
            void mouseReleaseEvent(QMouseEvent* e);
        
            void dragButtonPressed();
        
        };
        

        Don't put function name in "" ??? The function sig:

        QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)

        requires it to be in ""

        David

        JonBJ 1 Reply Last reply
        0
        • PerdrixP Perdrix

          Yes, yes and yes!

          #include <QObject>
          class DEditStars :
              public QObject
          {
              Q_OBJECT
          
          typedef QObject
                  Inherited;
          
          public:
              DEditStars() :
                  QObject()
              {
              };
          
              virtual ~DEditStars() {};
          
          public slots:
              void mousePressEvent(QMouseEvent* e);
              void mouseMoveEvent(QMouseEvent* e);
              void mouseReleaseEvent(QMouseEvent* e);
          
              void dragButtonPressed();
          
          };
          

          Don't put function name in "" ??? The function sig:

          QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)

          requires it to be in ""

          David

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

          @Perdrix

          • What type is your editor?
          • Do a delete of all files in your debug/release directory, and rebuild. Qt can get in a mess over its Q_OBJECT macros and other things, sometimes this happens and this fixes.
          • typedef QObject Inherited;: probably irrelevant, just wondering whether this could have any detrimental effect on moc etc.
          • dragButtonPressed is a slot of your own you have created?

          Oh, you didn't make clear:

          I'm getting a debug output message:

          QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed

          At first I thought you meant at compile-time, now I'm thinking you mean at runtime when the addAction() is hit?

          In any case please do the complete rebuild before going any further....

          1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by Perdrix
            #6

            Editor is of type DEditStars as you might hope.

            Never had a problem using that sort of typedef before.

            Yes this is at RUNTIME when addAction is invoked (after a full cleanup and rebuild):

            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                QPixmap p("C:\\Users\\amonra\\Documents\\Astrophotography\\NGC 7789 Caroline's Rose or Herschel's Spiral Cluster\\NGC7789 Edited large.png");
                DSSImageWidget w(p);
                DEditStars editor;
                QObject::connect(&w, &DSSImageWidget::Image_mousePressEvent, &editor, &DEditStars::mousePressEvent);
                QToolBar t(&w);
                QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp");
                t.setOrientation(Qt::Vertical);
                t.addAction(dragRect, "", &editor, "dragButtonPressed()");
                //t.setFixedSize(50, 50);
                t.setIconSize(QSize(48, 48));
                w.setToolBar(&t);
                w.show();
                return a.exec();
            }
            

            Debug log snippet:

            'DSSImageWidget.exe' (Win32): Loaded 'C:\Qt\5.15.0\msvc2019_64\plugins\imageformats\qwebpd.dll'. Symbols loaded.
            QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed()
            'DSSImageWidget.exe' (Win32): Loaded 'C:\Windows\System32\d3d9.dll'. 
            
            
            JonBJ jsulmJ 2 Replies Last reply
            0
            • PerdrixP Perdrix

              Editor is of type DEditStars as you might hope.

              Never had a problem using that sort of typedef before.

              Yes this is at RUNTIME when addAction is invoked (after a full cleanup and rebuild):

              int main(int argc, char *argv[])
              {
                  QApplication a(argc, argv);
                  QPixmap p("C:\\Users\\amonra\\Documents\\Astrophotography\\NGC 7789 Caroline's Rose or Herschel's Spiral Cluster\\NGC7789 Edited large.png");
                  DSSImageWidget w(p);
                  DEditStars editor;
                  QObject::connect(&w, &DSSImageWidget::Image_mousePressEvent, &editor, &DEditStars::mousePressEvent);
                  QToolBar t(&w);
                  QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp");
                  t.setOrientation(Qt::Vertical);
                  t.addAction(dragRect, "", &editor, "dragButtonPressed()");
                  //t.setFixedSize(50, 50);
                  t.setIconSize(QSize(48, 48));
                  w.setToolBar(&t);
                  w.show();
                  return a.exec();
              }
              

              Debug log snippet:

              'DSSImageWidget.exe' (Win32): Loaded 'C:\Qt\5.15.0\msvc2019_64\plugins\imageformats\qwebpd.dll'. Symbols loaded.
              QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed()
              'DSSImageWidget.exe' (Win32): Loaded 'C:\Windows\System32\d3d9.dll'. 
              
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #7

              @Perdrix

              • So editor is of type DEditStars and not DEditStars *, right?

              • I certainly would not expect it to work with "dragButtonPressed()", it would need to be "dragButtonPressed" as you showed originally.

              • (Temporarily) give up on this constructor. Create the action with an overload which does not take that, and set the signal/slot on the QAction's triggered after it is created. Can you get that to work?

              P.S.
              [signal]void QAction::triggered(bool checked = false)

              Your problem may (well?) be that you need your dragButtonPressed() slot to be declared with that (optional) parameter, in order to match correctly?

              1 Reply Last reply
              0
              • PerdrixP Perdrix

                Editor is of type DEditStars as you might hope.

                Never had a problem using that sort of typedef before.

                Yes this is at RUNTIME when addAction is invoked (after a full cleanup and rebuild):

                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    QPixmap p("C:\\Users\\amonra\\Documents\\Astrophotography\\NGC 7789 Caroline's Rose or Herschel's Spiral Cluster\\NGC7789 Edited large.png");
                    DSSImageWidget w(p);
                    DEditStars editor;
                    QObject::connect(&w, &DSSImageWidget::Image_mousePressEvent, &editor, &DEditStars::mousePressEvent);
                    QToolBar t(&w);
                    QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp");
                    t.setOrientation(Qt::Vertical);
                    t.addAction(dragRect, "", &editor, "dragButtonPressed()");
                    //t.setFixedSize(50, 50);
                    t.setIconSize(QSize(48, 48));
                    w.setToolBar(&t);
                    w.show();
                    return a.exec();
                }
                

                Debug log snippet:

                'DSSImageWidget.exe' (Win32): Loaded 'C:\Qt\5.15.0\msvc2019_64\plugins\imageformats\qwebpd.dll'. Symbols loaded.
                QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed()
                'DSSImageWidget.exe' (Win32): Loaded 'C:\Windows\System32\d3d9.dll'. 
                
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @Perdrix said in Debug output when calling QToolBar::addAction():

                QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed()

                This tells you exactly what the problem is.
                It should be:

                t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Perdrix said in Debug output when calling QToolBar::addAction():

                  QObject::connect: Use the SLOT or SIGNAL macro to connect DEditStars::dragButtonPressed()

                  This tells you exactly what the problem is.
                  It should be:

                  t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #9

                  @jsulm
                  The OP is trying to use the following overload:

                  QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)
                  

                  https://doc.qt.io/qt-5/qtoolbar.html#addAction-3

                  The action's triggered() signal is connected to member in receiver.

                  Note how the last argument is of type const char *, for the name of a member function.

                  jsulmJ 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @jsulm
                    The OP is trying to use the following overload:

                    QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)
                    

                    https://doc.qt.io/qt-5/qtoolbar.html#addAction-3

                    The action's triggered() signal is connected to member in receiver.

                    Note how the last argument is of type const char *, for the name of a member function.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #10

                    @JonB He still has to use SLOT, see https://doc.qt.io/qt-5/qobject.html#connect - it has char* also, but you have to use SLOT/SIGNAL macros, not just plain string containing slot/signal name.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    JonBJ 1 Reply Last reply
                    3
                    • jsulmJ jsulm

                      @JonB He still has to use SLOT, see https://doc.qt.io/qt-5/qobject.html#connect - it has char* also, but you have to use SLOT/SIGNAL macros, not just plain string containing slot/signal name.

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

                      @jsulm

                      but you have to use SLOT/SIGNAL macros, not just plain string containing slot name.

                      Ohhh, well that's not very clear from the docs: "the name of a member function" :) I took the docs as indicating as he did in his original post!

                      @Perdrix
                      So follow @jsulm's answer! Though TBH you would be far better getting rid of all SIGNAL/SLOT() macros/methods, and doing it new-style, as I say over & over in this forum :) Then the issue would not arise....

                      P.S.
                      That would be template <typename Functor> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor), overload https://doc.qt.io/qt-5/qtoolbar.html#addAction-7.

                      jsulmJ 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @jsulm

                        but you have to use SLOT/SIGNAL macros, not just plain string containing slot name.

                        Ohhh, well that's not very clear from the docs: "the name of a member function" :) I took the docs as indicating as he did in his original post!

                        @Perdrix
                        So follow @jsulm's answer! Though TBH you would be far better getting rid of all SIGNAL/SLOT() macros/methods, and doing it new-style, as I say over & over in this forum :) Then the issue would not arise....

                        P.S.
                        That would be template <typename Functor> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor), overload https://doc.qt.io/qt-5/qtoolbar.html#addAction-7.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @JonB said in Debug output when calling QToolBar::addAction():

                        getting rid of all SIGNAL/SLOT()

                        this!

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • PerdrixP Offline
                          PerdrixP Offline
                          Perdrix
                          wrote on last edited by Perdrix
                          #13

                          In the context of that code I tried:

                          t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed());
                          

                          and was awarded this nastygram:

                          1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17,53): error C2352: 'DEditStars::dragButtonPressed': illegal call of non-static member function
                          1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\deditstars.h(61): message : see declaration of 'DEditStars::dragButtonPressed'
                          

                          trying with:

                          t.addAction(dragRect, "", &editor, &editor.dragButtonPressed());
                          

                          got me:

                          1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17): error C2102: '&' requires l-value
                          

                          This:

                              t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
                          

                          Does work, but it definitely is NOT clear that what you need to code from the docs. If you want me to use the other formats - how do they go?
                          So hows it supposed to go?

                          B Pl45m4P JonBJ 3 Replies Last reply
                          0
                          • PerdrixP Perdrix

                            In the context of that code I tried:

                            t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed());
                            

                            and was awarded this nastygram:

                            1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17,53): error C2352: 'DEditStars::dragButtonPressed': illegal call of non-static member function
                            1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\deditstars.h(61): message : see declaration of 'DEditStars::dragButtonPressed'
                            

                            trying with:

                            t.addAction(dragRect, "", &editor, &editor.dragButtonPressed());
                            

                            got me:

                            1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17): error C2102: '&' requires l-value
                            

                            This:

                                t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
                            

                            Does work, but it definitely is NOT clear that what you need to code from the docs. If you want me to use the other formats - how do they go?
                            So hows it supposed to go?

                            B Offline
                            B Offline
                            Bonnie
                            wrote on last edited by
                            #14

                            @Perdrix
                            Do you know how to call connect?
                            It is exactly the same...

                            1 Reply Last reply
                            0
                            • PerdrixP Perdrix

                              In the context of that code I tried:

                              t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed());
                              

                              and was awarded this nastygram:

                              1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17,53): error C2352: 'DEditStars::dragButtonPressed': illegal call of non-static member function
                              1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\deditstars.h(61): message : see declaration of 'DEditStars::dragButtonPressed'
                              

                              trying with:

                              t.addAction(dragRect, "", &editor, &editor.dragButtonPressed());
                              

                              got me:

                              1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17): error C2102: '&' requires l-value
                              

                              This:

                                  t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
                              

                              Does work, but it definitely is NOT clear that what you need to code from the docs. If you want me to use the other formats - how do they go?
                              So hows it supposed to go?

                              Pl45m4P Offline
                              Pl45m4P Offline
                              Pl45m4
                              wrote on last edited by Pl45m4
                              #15

                              @Perdrix

                              &DEditStars::dragButtonPressed

                              New syntax without ( )


                              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                              ~E. W. Dijkstra

                              1 Reply Last reply
                              1
                              • PerdrixP Perdrix

                                In the context of that code I tried:

                                t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed());
                                

                                and was awarded this nastygram:

                                1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17,53): error C2352: 'DEditStars::dragButtonPressed': illegal call of non-static member function
                                1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\deditstars.h(61): message : see declaration of 'DEditStars::dragButtonPressed'
                                

                                trying with:

                                t.addAction(dragRect, "", &editor, &editor.dragButtonPressed());
                                

                                got me:

                                1>C:\Users\amonra\Documents\source\repos\QImageView\QImageView\main.cpp(17): error C2102: '&' requires l-value
                                

                                This:

                                    t.addAction(dragRect, "", &editor, SLOT(dragButtonPressed()));
                                

                                Does work, but it definitely is NOT clear that what you need to code from the docs. If you want me to use the other formats - how do they go?
                                So hows it supposed to go?

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

                                @Perdrix said in Debug output when calling QToolBar::addAction():
                                Just to be 100% clear, and get you on the right track of new syntax so you will like it(!), as @Pl45m4 has said the whole line needs to be:

                                t.addAction(dragRect, "", &editor, &DEditStars::dragButtonPressed);
                                

                                Page https://wiki.qt.io/New_Signal_Slot_Syntax gives you comparative examples.

                                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