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. SLOT connection problem

SLOT connection problem

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.4k 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.
  • ShodanS Offline
    ShodanS Offline
    Shodan
    wrote on last edited by Shodan
    #1

    Hi

    I d'like to run external *.exe files in my program.

    There is one error:
    QObject::connect: No such slot QWidget::runCleaner() in ..\Tests\arcMainWindow.cpp:11
    But the slot is there.

    When I run the programm, the window opens, and of course, nothing happens when the button is pushed.

    Here is the code:


    Tests.pro

    QT += widgets
    
    SOURCES += \
        main.cpp \
        arcMainWindow.cpp
    
    HEADERS += \
        arcMainWindow.h
    

    arcMainWindow.h

    #ifndef MYWINDOW_H
    #define MYWINDOW_H
    
    #include <QApplication>
    #include <QWidget>
    #include <QPushButton>
    #include <QProcess>
    #include <QObject>
    
    class arcMainWindow : public QWidget // On hérite de QWidget
    {
        public:
        arcMainWindow();
    
        public slots:
        void runCleaner();
    
        private:
        QPushButton *m_btn;
    };
    
    #endif // MYWINDOW_H
    

    main.cpp

    #include "arcMainWindow.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        arcMainWindow mainWindow;
        mainWindow.show();
    
        return app.exec();
    }
    

    arcMainWindow.cpp

    #include "arcMainWindow.h"
    
    arcMainWindow::arcMainWindow() : QWidget()
    {
        setFixedSize(300, 150);
    
        m_btn = new QPushButton("CCleaner", this);
        m_btn->setFont(QFont("Comic Sans MS", 14));
        m_btn->setCursor(Qt::PointingHandCursor);
        m_btn->move(60, 50);
        QObject::connect(m_btn, SIGNAL(clicked()), this, SLOT(runCleaner()));
    }
    
    void arcMainWindow::runCleaner()
    {
        QProcess *myProcess = new QProcess();
        myProcess->start( "\"C:\\Program Files\\CCleaner\\CCleaner.exe\"" );
    }
    

    Any ideas??

    Thanks in advance =)

    D 1 Reply Last reply
    0
    • ShodanS Shodan

      Hi

      I d'like to run external *.exe files in my program.

      There is one error:
      QObject::connect: No such slot QWidget::runCleaner() in ..\Tests\arcMainWindow.cpp:11
      But the slot is there.

      When I run the programm, the window opens, and of course, nothing happens when the button is pushed.

      Here is the code:


      Tests.pro

      QT += widgets
      
      SOURCES += \
          main.cpp \
          arcMainWindow.cpp
      
      HEADERS += \
          arcMainWindow.h
      

      arcMainWindow.h

      #ifndef MYWINDOW_H
      #define MYWINDOW_H
      
      #include <QApplication>
      #include <QWidget>
      #include <QPushButton>
      #include <QProcess>
      #include <QObject>
      
      class arcMainWindow : public QWidget // On hérite de QWidget
      {
          public:
          arcMainWindow();
      
          public slots:
          void runCleaner();
      
          private:
          QPushButton *m_btn;
      };
      
      #endif // MYWINDOW_H
      

      main.cpp

      #include "arcMainWindow.h"
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          arcMainWindow mainWindow;
          mainWindow.show();
      
          return app.exec();
      }
      

      arcMainWindow.cpp

      #include "arcMainWindow.h"
      
      arcMainWindow::arcMainWindow() : QWidget()
      {
          setFixedSize(300, 150);
      
          m_btn = new QPushButton("CCleaner", this);
          m_btn->setFont(QFont("Comic Sans MS", 14));
          m_btn->setCursor(Qt::PointingHandCursor);
          m_btn->move(60, 50);
          QObject::connect(m_btn, SIGNAL(clicked()), this, SLOT(runCleaner()));
      }
      
      void arcMainWindow::runCleaner()
      {
          QProcess *myProcess = new QProcess();
          myProcess->start( "\"C:\\Program Files\\CCleaner\\CCleaner.exe\"" );
      }
      

      Any ideas??

      Thanks in advance =)

      D Offline
      D Offline
      Devopia53
      wrote on last edited by Devopia53
      #2

      @Shodan

      Hi.

      You are missing Q_OBJECT macro in the arcMainWindow.h.
      The Q_OBJECT is required to use Signal & Slots.

      like this:

      class arcMainWindow : public QWidget // On hérite de QWidget
      {
          Q_OBJECT
      
          public:
          arcMainWindow();
      
      1 Reply Last reply
      2
      • ShodanS Offline
        ShodanS Offline
        Shodan
        wrote on last edited by Shodan
        #3

        This is it!

        At the begining I had the Q_OBJECT macro in the arcMainWindow.h file, but I had a lot of errors.
        Certainly because I forgot to run qmake...?

        I spent hours on that... :-)

        Merci beaucoup

        1 Reply Last reply
        0
        • ShodanS Offline
          ShodanS Offline
          Shodan
          wrote on last edited by
          #4

          Well, maybe it is a stupid question, but I try to understand...

          My misstake was to forget to add Q_OBJECT macro in the arcMainWindow.h and to run qmake. OK

          I cleared the Q_OBJECT macro to get back the "no such SLOT" error.
          Then I added QT += core to the .pro file and Q_OBJECT to the .h file and it seems also to work .

          What difference does this make?

          D 1 Reply Last reply
          1
          • ShodanS Shodan

            Well, maybe it is a stupid question, but I try to understand...

            My misstake was to forget to add Q_OBJECT macro in the arcMainWindow.h and to run qmake. OK

            I cleared the Q_OBJECT macro to get back the "no such SLOT" error.
            Then I added QT += core to the .pro file and Q_OBJECT to the .h file and it seems also to work .

            What difference does this make?

            D Offline
            D Offline
            Devopia53
            wrote on last edited by
            #5

            @Shodan

            Even if you add Q_OBJECT to the arcMainWindow.h, qmake will not run automatically when you build it.
            The qmake will run automatically upon build when the .pro file is modified.

            1 Reply Last reply
            1
            • ShodanS Offline
              ShodanS Offline
              Shodan
              wrote on last edited by
              #6

              Okay. Thanks.

              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