PDA

View Full Version : [Help] QObject::connect



vinny gracindo
20th October 2009, 11:20
I have the following function:


void MainWindow::OpenWindow(char a) {
Ui_Form_Usuario* wig;
switch(a) {
case 1: {
wig = new Ui_Form_Usuario;
break;
}
case 'b': {
wig = new Ui_Form_Motorista
break;
}
}
QWidget* owig = new QWidget(this);
wig->setupUi(owig);
owig->show();
}


If I pass parameter in the connection, it is underlined with a line. (It compiles, but does not work out).


QObject::connect(action_Usu_rio, SIGNAL(activated()), MainWindow, SLOT(OpenWindow()));


If I put in the function as openWindow a= 'u', go right and it opens a form.

help

spirit
20th October 2009, 11:40
probably you should rewrite you connection like this


QObject::connect(wig->action_Usu_rio, SIGNAL(activated()), this, SLOT(OpenWindow()));

scascio
20th October 2009, 13:09
If you need to connect a SIGNAL to a SLOT with parameters, arguments must match.
Dont write down their name since the connect failed.


//good connection
QObject::connect(sender, SIGNAL(mySignal(type1, type2)), receiver, SLOT(mySlot1(type1, type2)));
/*wrong connection with argument names
QObject::connect(sender, SIGNAL(mySignal(type1 arg1, type2 arg2)), receiver, SLOT(mySlot1(type1 arg1, type2 arg2))); */


Notice that you dont need to use them all :


QObject::connect(sender, SIGNAL(mySignal(type1)), receiver, SLOT(mySlot2(type1)));

With a default parameter in your OpenWindow function, your connect should work

I hope I understood your problem.

wagmare
20th October 2009, 13:26
did u miss Q_OBJECT macro ...?