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. signal is not working
Forum Updated to NodeBB v4.3 + New Features

signal is not working

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 7 Posters 1.5k Views 3 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.
  • F frnklu20

    Hi,

    In my program there are 2 basic classes, DiagramScene and MainWindow.
    What i'm trying to do is to emit a signal from the DiagramScene to my MainWindow but the sinal is not recieved.

    DiagramScene.h

    void addtreeitem( QIcon, DiagramItem *item);
    

    DiagramScene.cpp

    emit addtreeitem(QIcon("C:/Users/Lukas/Desktop/simulight/images/barramento"),item);
    

    MainWindow.h

    public slots:
       void addtreeitem( QIcon, DiagramItem *item);
    

    MainWindow.cpp

    MainWindow::MainWindow()
    {
     scene = new DiagramScene(itemMenu, this);
    connect(scene, SIGNAL(addtreeitem(QIcon, DiagramItem *item);),
                this, SLOT(addtreeitem(QIcon, DiagramItem *item)));
    }
    
    ...
    void MainWindow::addtreeitem( QIcon icon, DiagramItem *item)
    {
        QString name=item->data(0).toString();
        addTreeEquip(tree->selectedItems()[0],name,icon);
    
        QMessageBox msg;
        msg.setText("ok");//to test if the signal is being emitted
        msg.exec();
    }
    

    i don't know why this is wrong :(

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by aha_1980
    #2

    @frnklu20

    connect(scene, SIGNAL(addtreeitem(QIcon, DiagramItem *item);), this, SLOT(addtreeitem(QIcon, DiagramItem *item)));

    • this code cannot compile
    • you don't check the result of connect
    • you should prefer the new functor connect syntax
    • Inside SIGNAL and SLOT only types should be given, no variable names

    Regards

    Qt has to stay free or it will die.

    1 Reply Last reply
    5
    • F Offline
      F Offline
      frnklu20
      wrote on last edited by
      #3
      connect(scene, SIGNAL(addtreeitem(QIcon, DiagramItem*);),
                  this, SLOT(addtreeitem(QIcon, DiagramItem*)));
      

      I already changed this but still doesn't work. How can I check the result of connect?

      1 Reply Last reply
      0
      • F Offline
        F Offline
        frnklu20
        wrote on last edited by
        #4

        and I don't if it makes any difference, but the signal is emitted from a mousePressEvent function

        Pablo J. RoginaP 1 Reply Last reply
        0
        • F frnklu20

          and I don't if it makes any difference, but the signal is emitted from a mousePressEvent function

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by Pablo J. Rogina
          #5

          @frnklu20

          DiagramScene.h

          void addtreeitem( QIcon, DiagramItem *item);

          Please show more context about this header file, i.e. where/how the signal: keyword is used before this definition

          As @aha_1980 suggested please make the effort to try using the new signal & slots syntax. It helps showing any errors during compile-time so it's easier to spot what could be wrong with the signal and slots connections.

          In addition, I'd suggest that you don't use the same name for the slot as the signal. Usually something like handleSignalName is easier to follow, i.e. handleAddTreeItem() in your case.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          5
          • F Offline
            F Offline
            frnklu20
            wrote on last edited by frnklu20
            #6

            Hi,

            DiagramScene.h

            class DiagramScene : public QGraphicsScene
            {
                Q_OBJECT
            ...
            signals:
                void itemInserted(DiagramItem *item);
                void textInserted(QGraphicsTextItem *item);
                void clicked();
                void addtreeitem(DiagramItem *item);//here is the signal
            ....
            };
            

            that's it

            How can i write it with the new sintax?
            When i execute the program it says "QObject::connect: No such signal DiagramScene::addtreeitem(DiagramItem*);"

            PS: i changed the input of the signal and the slot to only DiagramItem*

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #7

              @frnklu20 said in signal is not working:

              SIGNAL(addtreeitem(QIcon, DiagramItem*);

              I don't see such a signal in your header (apart from the fact that the semicolon is absolutely wrong there). As already wrote above: Use the new signal/slot syntax or properly check the return value of QObject::connect() / take a look at the console output during runtime and you will notice that there is no such a signal at all.

              /edit: did not saw you last comment about the change of the signal, but the rest of my comments is still valid.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • F Offline
                F Offline
                frnklu20
                wrote on last edited by
                #8

                but how can i write it in the new sintax?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @frnklu20 said in signal is not working:

                  but how can i write it in the new sintax?

                  By looking into the documentation

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  3
                  • F Offline
                    F Offline
                    frnklu20
                    wrote on last edited by frnklu20
                    #10
                    connect(scene, &DiagramScene::addtreeitem),
                                this, &MainWindow::handleaddtreeitem);
                    

                    it gives me an error in addtreeitem, it says" error: no matching member function for call to 'connect'"

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      You are missing the & for the function parameters.

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

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        frnklu20
                        wrote on last edited by frnklu20
                        #12

                        yeah i fixed it! but it gives me an error in the connect

                        0_1568918552432_c8677482-2b41-434e-aa09-3928e4e4d1c3-image.png

                        if i put the &parameter in the objects it says cannot take the adress of an rvalue of type MainWindow and no matching member function for call to 'connect'

                        jsulmJ Pl45m4P 2 Replies Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          And what error exactly ?

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

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            frnklu20
                            wrote on last edited by
                            #14

                            in the no matching member it says:
                            mainwindow.cpp:25:5: error: no matching member function for call to 'connect'
                            qobject.h:228:43: note: candidate function template not viable: requires at least 4 arguments, but 2 were provided
                            qobject.h:260:13: note: candidate function template not viable: requires 3 arguments, but 2 were provided
                            qobject.h:269:13: note: candidate function template not viable: requires at least 4 arguments, but 2 were provided
                            qobject.h:300:13: note: candidate function template not viable: requires 3 arguments, but 2 were provided
                            qobject.h:308:13: note: candidate function template not viable: requires at least 4 arguments, but 2 were provided
                            qobject.h:463:41: note: candidate function not viable: requires at least 3 arguments, but 2 were provided
                            qobject.h:208:36: note: candidate function not viable: requires at least 4 arguments, but 2 were provided
                            qobject.h:211:36: note: candidate function not viable: requires at least 4 arguments, but 2 were provided

                            don't know what that means

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by Christian Ehrlicher
                              #15

                              Since you're doing the connect in a class which is not derived from QObject or in main() you have forgot 'QObject::' before connect since it's a static function of QObject

                              And you've a syntax error in your code - '&DiagramScene::addtreeitem),'

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              4
                              • F frnklu20

                                yeah i fixed it! but it gives me an error in the connect

                                0_1568918552432_c8677482-2b41-434e-aa09-3928e4e4d1c3-image.png

                                if i put the &parameter in the objects it says cannot take the adress of an rvalue of type MainWindow and no matching member function for call to 'connect'

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

                                @frnklu20 Don't put & in front of "this" - "this" is already a pointer. Currently you're passing pointer to pointer which is wrong here.

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

                                1 Reply Last reply
                                4
                                • F frnklu20

                                  yeah i fixed it! but it gives me an error in the connect

                                  0_1568918552432_c8677482-2b41-434e-aa09-3928e4e4d1c3-image.png

                                  if i put the &parameter in the objects it says cannot take the adress of an rvalue of type MainWindow and no matching member function for call to 'connect'

                                  Pl45m4P Offline
                                  Pl45m4P Offline
                                  Pl45m4
                                  wrote on last edited by
                                  #17
                                  This post is deleted!
                                  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