[SOLVED]Object::connect: No such slot...
-
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.
-
So what is the exact error message you get?
-
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 :-)