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. QObject::connect problem with argument list
Qt 6.11 is out! See what's new in the release blog

QObject::connect problem with argument list

Scheduled Pinned Locked Moved General and Desktop
20 Posts 7 Posters 9.8k 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.
  • S Offline
    S Offline
    sheehan1234
    wrote on last edited by
    #7

    It looks really useful, but I'm hoping to see if I can get this code to work before I erase all of it. The only problem now is a runtime error that says this in the command window:

    QObject::connect: No such slot QWidget::appendFileName()

    I do have appendFileName() declared a public slot and i have written the code that I want for the function itself

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sheehan1234
      wrote on last edited by
      #8

      Does anyone know why I'm getting that error?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kxyu
        wrote on last edited by
        #9

        Code please. I have a guess, but code first

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

          Public Declarations:
          @QFileSystemModel model;
          QTreeView tree;
          QString file;@

          The subroutine:
          @void MyWidget::appendFileName()
          {
          file.append((model.data(tree.currentIndex(), Qt::DisplayRole)).toString());
          fileAttained = true;
          }@

          In the main:
          @
          model.setRootPath(QDir::currentPath());
          tree.setModel(&model);
          QWidget *wid = new QWidget;
          button.setText("Select File");

          layout.addWidget(&tree);
          layout.addWidget(&button);

          wid->setLayout(&layout);
          wid->setFixedSize(1100, 500);
          wid->show();

          QObject::connect(&button, SIGNAL(clicked()), this, SLOT(appendFileName()));@

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kxyu
            wrote on last edited by
            #11

            I don't get it. So you define a class MyWidget, then instantiate just simple Widget object and after all use this pointer in main(). Altogether this makes no sense.

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

              that's my mistake, the main has a function call @widget.getFile();@ which is here:
              @void MyWidget::getFile()
              {
              model.setRootPath(QDir::currentPath());
              tree.setModel(&model);
              tree.setColumnWidth(0, 500);
              tree.resize(1000, 300);
              QWidget *wid = new QWidget;
              button.setText("Select File");

              layout.addWidget(&tree);
              layout.addWidget(&button);

              wid->setLayout(&layout);
              wid->setFixedSize(1100, 500);
              wid->show();

              QObject::connect(&button, SIGNAL(clicked()), this, SLOT(appendFileName()));

              }@

              Maybe this makes a bit more sense, I appreciate you helping. What was your guess?

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

                Did you declare appendFileName() as a slot in your class header?

                @
                class MyWidget {
                // ....

                protected slots:
                void appendFileName();

                };
                @

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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sheehan1234
                  wrote on last edited by
                  #14

                  yes sir I did

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

                    Then show us the complete code, please.

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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sheehan1234
                      wrote on last edited by
                      #16

                      @#include <QtGui>
                      #include <fstream>
                      #include <iostream>

                      using namespace std;

                      class MyWidget : public QWidget
                      {

                      public:
                      MyWidget();
                      float currX1, currX2, currY1, currY2, nextX1, nextX2, nextY1, nextY2;
                      float points[105][105];
                      QString file;
                      int numCols;
                      int numRows;
                      QFileSystemModel model;
                      QTreeView tree;
                      QVBoxLayout layout;
                      QPushButton button;
                      bool fileAttained;
                      void getFile();

                      protected slots:
                      void appendFileName();

                      protected:
                      void paintEvent(QPaintEvent *);

                      };

                      MyWidget::MyWidget()
                      {
                      QPalette palette(MyWidget::palette());
                      palette.setColor(backgroundRole(), Qt::white);
                      setPalette(palette);

                      }

                      void MyWidget::paintEvent(QPaintEvent *)
                      {
                      // omitted
                      }
                      void MyWidget::appendFileName()
                      {
                      file.append((model.data(tree.currentIndex(), Qt::DisplayRole)).toString());
                      fileAttained = true;
                      }
                      void MyWidget::getFile()
                      {
                      model.setRootPath(QDir::currentPath());
                      tree.setModel(&model);
                      tree.setColumnWidth(0, 500);
                      tree.resize(1000, 300);
                      QWidget *wid = new QWidget;
                      button.setText("Select File");

                      layout.addWidget(&tree);
                      layout.addWidget(&button);

                      wid->setLayout(&layout);
                      wid->setFixedSize(1100, 500);
                      wid->show();

                      QObject::connect(&button, SIGNAL(clicked()), this, SLOT(appendFileName()));
                      QObject::connect(&button, SIGNAL(clicked()), wid, SLOT(close()));

                      }
                      int main(int argc, char *argv[])
                      {
                      QApplication app(argc, argv);
                      MyWidget widget;
                      widget.getFile();

                          // omitted 
                      

                      return app.exec();
                      }
                      @

                      I have code commented out/ omitted from the post that does the second part of the program which is what relies on getting the name of the file that the user chooses

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #17

                        You missed the Q_OBJECT macro in your header file opf MyWidget:

                        @
                        class MyWidget : public QWidget
                        {
                        // this is missing
                        Q_OBJECT;
                        public:
                        MyWidget();
                        float currX1, currX2, currY1, currY2, nextX1, nextX2, nextY1, nextY2;
                        float points[105][105];

                        protected slots:
                        void appendFileName();

                        protected:
                        void paintEvent(QPaintEvent *);
                        };
                        @

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          sheehan1234
                          wrote on last edited by
                          #18

                          thank you, I had tried that and gotten errors so I thought it was wrong. so i tried again, got link errors, and I included "main.moc". Now there aren't link errors, but a the moc file has errors that I don't know how to fix. There are about 10 of them, heres the first to give you an example
                          @1>.\GeneratedFiles\Release\main.moc(42) : error C2653: 'MyWidget' : is not a class or namespace name@

                          I can copy the moc file too if you need it

                          1 Reply Last reply
                          0
                          • EddyE Offline
                            EddyE Offline
                            Eddy
                            wrote on last edited by
                            #19

                            Looks like you didn't include mywidget.h in your main.

                            Qt Certified Specialist
                            www.edalsolutions.be

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #20

                              Split up the class definition into a header file, and don't put definition and implemenation together in the cpp file.
                              then it should work.

                              Or include main.moc at the end of the file.

                              Nokia Certified Qt Specialist.
                              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                              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