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. Object::connect: No such slot QApplication::MYSLOT()

Object::connect: No such slot QApplication::MYSLOT()

Scheduled Pinned Locked Moved General and Desktop
13 Posts 8 Posters 32.1k Views 1 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.
  • P Offline
    P Offline
    patowlmc
    wrote on last edited by
    #1

    Well, I've searched this many times in Google, and still I can't solve it, so I ask for some help.

    I've seen the documentation, and I think this is the way to declare a custom slot:

    My H file:
    @
    #ifndef ACTIVIDADESTIC_H
    #define ACTIVIDADESTIC_H

    #include <QMainWindow>
    #include <QMessageBox>

    namespace Ui {
    class ActividadesTIC;

    }

    class ActividadesTIC : public QMainWindow
    {
    Q_OBJECT

    public:
    ActividadesTIC(): manera() {}
    explicit ActividadesTIC(QWidget *parent = 0);
    ~ActividadesTIC();

    public slots:
    void easy();

    private:
    int manera;
    Ui::ActividadesTIC *ui;
    };

    #endif // ACTIVIDADESTIC_H

    @

    My main.cpp
    @

    void ActividadesTIC::easy() {
    ++manera;
    if (manera>0) {
    this->setWindowTitle("This is the easy way");
    }
    }

    class MyWidget : public QWidget
    {
    public:
    MyWidget(QWidget *parent = 0);
    };

    MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    {
    setFixedSize(900, 700);

    QRadioButton *easyWay = new QRadioButton (tr("Easy Way"), this);
        easyWay->setFont(QFont("Arial", 11));
        easyWay->setGeometry(10, 40, 150, 50);
    
       connect(easyWay, SIGNAL(clicked()), this, SLOT(easy()));
    

    }

    int main(int argc, char *argv[])
    {

    QDir setPath("Documents");
    QApplication app(argc, argv);
        MyWidget widget;
        widget.show();
        return app.exec&#40;&#41;;
    

    }

    @

    Well, what i do in the void easy() doesn't really matters, its just a test to see if it works, but I keep getting Object::connect: No such slot QApplication::easy() in ..\ActividadesTIC\main.cpp

    So please, any help is welcome.

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      The problem is at this line:
      @connect(easyWay, SIGNAL(clicked()), qApp, SLOT(easy())); //the slot is in your class not in QApplication
      @
      So the correct 3rd argument of connect should be this (the instance of your class***):
      @connect(easyWay, SIGNAL(clicked()), this, SLOT(easy()));@

      LE:
      ***More correctly expressed: pointer to the instance

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marsupial
        wrote on last edited by
        #3

        The point is that easy() is not a slot of QApplication but of your own class ActividadesTIC. Thus you should write

        @connect ( easyWay, SIGNAL(clicked()), this, SLOT(easy()) );@

        Edit: I shouldn't let myself get distracted by something else while writing a post... Took 6 minutes to long :D

        1 Reply Last reply
        0
        • P Offline
          P Offline
          patowlmc
          wrote on last edited by
          #4

          Ok, so I've updated the program (& the post, you can check the "new code above"), but now I get this error: @Object::connect: No such slot QWidget::easy() in ..\ActividadesTIC\main.cpp:38@

          So now, i understand where's the problem. But how to fix it?

          NOTE: I tried: @connect ( easyWay, SIGNAL(clicked()), ActividadesTIC, SLOT(easy()) );@
          But it tells me: @expected primary expression before ',' token@

          1 Reply Last reply
          0
          • P Offline
            P Offline
            patowlmc
            wrote on last edited by
            #5

            FINALLY!!!

            Got it working guys.

            Do you expect me to post the working code? I'm doing so anyway: (NOTE: some of it is in spanish)

            O!! BTW: THANKS!!

            MY H FILE

            @
            #ifndef ACTIVIDADESTIC_H
            #define ACTIVIDADESTIC_H

            #include <QMainWindow>
            #include <QMessageBox>

            namespace Ui {
            class ActividadesTIC;

            }

            class MyWidget : public QWidget
            {
            Q_OBJECT

            public:
            MyWidget(QWidget *parent = 0);

            public slots:
            void easy();

            private:
            int manera;
            };

            class ActividadesTIC : public QMainWindow
            {
            // Q_OBJECT

            public:

            explicit ActividadesTIC(QWidget *parent = 0);
            ~ActividadesTIC();
            

            private:
            Ui::ActividadesTIC *ui;
            };

            #endif // ACTIVIDADESTIC_H

            @

            My main.cpp:
            @
            #ifndef ACTIVIDADESTIC_H
            #define ACTIVIDADESTIC_H

            #include <QMainWindow>
            #include <QMessageBox>

            namespace Ui {
            class ActividadesTIC;

            }

            class MyWidget : public QWidget
            {
            Q_OBJECT

            public:
            MyWidget(QWidget *parent = 0);

            public slots:
            void easy();

            private:
            int manera;
            };

            class ActividadesTIC : public QMainWindow
            {
            // Q_OBJECT

            public:

            explicit ActividadesTIC(QWidget *parent = 0);
            ~ActividadesTIC();
            

            private:
            Ui::ActividadesTIC *ui;
            };

            #endif // ACTIVIDADESTIC_H

            @

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Please do yourself a favor and include the Q_OBJECT macro in all QObject derived classes (QWidgets and subclasses count in!). You will save you a big bunch of problems, even if you do not need the functionality in the first place. So, please remove the commenting // in the second class.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • P Offline
                P Offline
                patowlmc
                wrote on last edited by
                #7

                hahah, ok Thanks, And I'll do that from now and on

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ReaMix
                  wrote on last edited by
                  #8

                  When you posted your solution, you pasted the header file in the cpp section. I am having the same problem and am unable to resolve. I would appreciate seeing your working cpp code, if you still have it on hand.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    Please open a new thread and post your problem description with some code snippets there.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sushant
                      wrote on last edited by
                      #10

                      Error :----QObject::connect: No such slot QDialog::mydata()

                      My HeaderFile
                      #ifndef DIALOG_H
                      #define DIALOG_H
                      #include <QDialog>
                      #include<QLineEdit>
                      #include<QPushButton>

                      class Dialog : public QDialog
                      {

                      public:
                      Dialog(QLineEdit *);
                      QPushButton *apply;
                      QLineEdit *line2;
                      QLineEdit *oldLineEdit;
                      private slots:
                      void mydata();

                      };

                      #endif // DIALOG_H

                      cpp file

                      #include "Dialog.h"
                      #include <QVBoxLayout>
                      #include<stdio.h>
                      Dialog::Dialog(QLineEdit *ledit)
                      {
                      apply = new QPushButton("Apply");
                      line2 = new QLineEdit;
                      oldLineEdit=ledit;
                      QVBoxLayout *b = new QVBoxLayout;
                      b->addWidget(line2);
                      b->addWidget(apply);
                      setLayout(b);
                      QObject::connect(apply,SIGNAL(clicked()),this,SLOT(mydata()));
                      }

                      void Dialog::mydata(){
                      printf("Enter the slot");
                      QString str = line2->text();
                      oldLineEdit->setText(str);
                      }

                      1 Reply Last reply
                      0
                      • IamSumitI Offline
                        IamSumitI Offline
                        IamSumit
                        wrote on last edited by
                        #11

                        hii Sushant......
                        It is inadequate --
                        QObject::connect(apply,SIGNAL),this,SLOT)); ?

                        Be Cute

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          sushant
                          wrote on last edited by
                          #12

                          hii sumit,
                          QObject::connect(apply,SIGNAL(clicked()),this,SLOT(mydata()));

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            dbzhang800
                            wrote on last edited by
                            #13

                            Hi sushant,

                            1. You forget add Q_OBJECT in your custom class.
                            2. Please wrap your code between <code>@ and @<code>

                            BTW,
                            You can start a new thread for your question next time.

                            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