Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]Object::connect: No such slot...

    General and Desktop
    3
    4
    5575
    Loading More Posts
    • 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.
    • A
      Alterah last edited by

      Hello, I have been slowly working on a program and I am running into this particular issue. I am using Qt Creator on Windows XP.

      Here's the code:

      usernamepopup.h
      @
      #ifndef USERNAMEPOPUP_H
      #define USERNAMEPOPUP_H

      #include <QtGui>
      #include <QWidget>

      class UsernamePopup : public QWidget
      {
      Q_OBJECT
      public:
      UsernamePopup();

      protected:
      QLabel *mIntroText;
      QLineEdit *mUsernameEntry;
      QLineEdit *mPasswordEntry;
      QLineEdit *mPasswordCheckEntry;

      void handleCancelClicked();
      void handleOkClicked();
      

      };

      #endif // USERNAMEPOPUP_H
      @

      usernamepopup.cpp (I've removed some extra widgets to make this easier to view. I can post full code, but think this will be easier to view)

      @
      #include "usernamepopup.h"

      UsernamePopup::UsernamePopup()
      {
      //Set size
      const int WIDTH = 300;
      const int HEIGHT = 180;

      int screenWidth;
      int screenHeight;
      
      QDesktopWidget *desktop = new QDesktopWidget;
      
      //Get size of the "first" monitor. This will ensure
      //the window is displayed centered on the primary monitor
      screenWidth = desktop->screenGeometry(0).width();
      screenHeight = desktop->screenGeometry(0).height();
      
      QPushButton *mOkButton = new QPushButton("OK");
      mOkButton->setFixedHeight(30);
      mOkButton->setFixedWidth(75);
      connect(mOkButton, SIGNAL(clicked()), this, SLOT(handleOkClicked()));
      
      QPushButton *mCancelButton = new QPushButton("Cancel");
      mCancelButton->setFixedHeight(30);
      mCancelButton->setFixedWidth(75);
      connect(mCancelButton, SIGNAL(clicked()), qApp, SLOT(quit()));
      
      QVBoxLayout *mMainLayout = new QVBoxLayout();
      mMainLayout->setAlignment(Qt::AlignTop);
      
      QHBoxLayout *mButtonLayout = new QHBoxLayout();
      mButtonLayout->addWidget(mOkButton);
      mButtonLayout->addWidget(mCancelButton);
      
      mMainLayout->addLayout(mButtonLayout);
      
      setLayout(mMainLayout);
      
      //set size
      resize(WIDTH, HEIGHT);
      
      //center window
      move((screenWidth - WIDTH) / 2, (screenHeight - HEIGHT) / 2);
      
      setWindowFlags( Qt::WindowStaysOnTopHint );
      

      }

      void UsernamePopup::handleOkClicked()
      {
      QString username;
      QString password;

      username = mUsernameEntry->text();
      
      if(mPasswordEntry->text() == mPasswordCheckEntry->text())
      {
          password = mPasswordEntry->text();
          mIntroText->setText("Passwords match!");
      }
      else
      {
          mIntroText->setText("Passwords do not match");
      }
      

      }
      @

      I am not sure what is going on here. I've tried running qMake beforehand but that seems to have no effect. Thanks for any help.

      1 Reply Last reply Reply Quote 0
      • T
        tobias.hunger last edited by

        So what is the exact error message you get?

        1 Reply Last reply Reply Quote 0
        • G
          giesbert last edited by

          Hi,

          the error is in your header file, you have not declared the slots to be slots:

          @
          #ifndef USERNAMEPOPUP_H
          #define USERNAMEPOPUP_H

          #include <QtGui>
          #include <QWidget>

          class UsernamePopup : public QWidget
          {
          Q_OBJECT
          public:
          UsernamePopup();

          protected:
          QLabel *mIntroText;
          QLineEdit *mUsernameEntry;
          QLineEdit *mPasswordEntry;
          QLineEdit *mPasswordCheckEntry;

          protected slots: // <-- this was missing
          void handleCancelClicked();
          void handleOkClicked();
          };

          #endif // USERNAMEPOPUP_H
          @

          For the next time, you should also describe your problem in the text, pehaps with a full error message :-)

          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 Reply Quote 0
          • A
            Alterah last edited by

            Whoops. Sorry for not including the exact error message. And, thank you for your assistance. I did not realize you had to declare the slots to be slots. Thanks again.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post