QT : CONNECT

hi!
i have this class in my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Ui_MainWindow
{
public slots:
	void entrancePage();
public:
    QWidget *centralwidget;
    QPushButton *pushButton;
    QLabel *label;
    QLabel *label_2;
    QLineEdit *lineEdit;
    QLineEdit *lineEdit_2;
    QStatusBar *statusbar;

    void setupUi(QMainWindow *MainWindow)
    {
  .
  .
  .
 QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(entrancePage()));
 QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(entrancePage()));
}
}

and i define entrance() as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Ui_MainWindow::entrancePage(vector<User*>& users){
	vector<User*> users;
	User* admin=new User("admin","admin",0);
	users.push_back(admin);
	QString qname=lineEdit->text();
	QString qpass=lineEdit_2->text();
	string name=qname.toStdString();
	string pass=qpass.toStdString();
		if(isCorrectInfo(name,pass,users)){
			User* user=findUser(name,pass,users);
			user->login();
			QTextStream out(stdout);
			out<<"you are logged in!"<<endl;
			user->mainmenu(users);
			}

and i have this code in my main():
1
2
3
4
5
6
7
8
9
int main(int argc, char **argv){
	
	QApplication app(argc, argv);
	Ui_MainWindow* um=new Ui_MainWindow();
	QMainWindow* window=new QMainWindow();
	um->setupUi(window);
	window->show();
	return app.exec();
	}

but i got this compile time error:
error: no matching function for call to ‘QObject::connect(QPushButton*&, const char [11], Ui_MainWindow* const, const char [16])’
can anyone help me?!
I'm fairly certain that you need to set up your Ui_MainWindow class to have signal and slot mechanisms. The easiest way would be to change your code to something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Ui_MainWindow : QObject {
        Q_OBJECT;

    public slots:
        void entrancePage();

    public:
        // ...

        void setupUi(QMainWindow* mainWindow) {
            // ...
            connect(pushButton, SIGNAL(clicked()), this, SLOT(entrancePage()));
            // why twice? 
        }
};
thanks a lot!!
now it works.. :)
How did you create the class Ui_MainWindow?

With Designer, "direct approach"?
http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
another question!
in entrancePage() function i wanna show another page instead of writing a message in the console..but i have no idea how to do this..
should my classes inherit from QObject or QWidget??
should i create a new QMainWindow ??
i am using Qt designer for creating my pages..
How about a different approach?

Make that "next page" the central widget of your main window. Set it disabled/hidden at start.

Create a separate "login" dialog. Show it at start. Connect the "successfully closing" signal of the dialog into a slot of the main window that enables the central widget.
Topic archived. No new replies allowed.