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. [SOLVED]Object::connect: No such slot...
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.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.
  • A Offline
    A Offline
    Alterah
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      So what is the exact error message you get?

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

        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
        0
        • A Offline
          A Offline
          Alterah
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved