PDA

View Full Version : Slots and Connection of Forms...



steve.bush
19th March 2011, 07:37
Hi,

So I have a standalone application which has a QMainWindow. I created another application which is also a QMainWindow. I tried linking them using a button but it did not work. I then changed the second application to QDialog and then the button worked! But since I changed it from QMainWindow to QDialog, the slots stopped working on the new application (I guess the dialog cannot have many buttons..)

Anyway, how do I get this working so that the first QMainWindow opens the second QMainWindow or QDialog AND the buttons in the second application still work..?

Thanks.

Lykurg
19th March 2011, 09:12
It does not matter if it is a QDialog or a QMainWindow. So can you show us your code which is not working for both solution.

steve.bush
19th March 2011, 09:56
First app: MainWin




MainWin::MainWin(QWidget*p, Qt::WindowFlags f):QMainWindow(p,f)
{
dSecond = NULL; // QDialog
ui.setupUi(this);
connect(ui.action_Two, SIGNAL(activated()), this, SLOT(two()));
}

MainWin::~MainWin()
{
}

void MainWin::two()
{
if(!dSecond)
{
dSecond = new QDialog(this);
uiSecond.setupUi(dSecond); //ui::Second uiSecond;
}
dSecond->exec();
}



Second app: Second




Second::Second(QWidget *parent) :
QDialog(parent),
ui(new Ui::Second)
{
connect(ui->action_button, SIGNAL(clicked()), this, SLOT(func_clicked()));
}

discovery::~discovery()
{
delete ui;
}

void discovery::func_clicked()
{
QMessageBox::warning(0,"Test", "Test message. It works!");
}



This way shows the new app when the menu bar item is clicked, but the new app does not show warning message when button is pressed.

Rhayader
20th March 2011, 01:40
in second the SLOT is a
void Second::func_clicked()
and you have a
void discovery::func_clicked()
Maybe the discovery is a relic from the previous implemantation?
(the same for the destructor. Does it compile???)

Check this:
http://www.qtcentre.org/faq.php?faq=qt_signalslot

ChrisW67
20th March 2011, 04:20
If these two QWidgets are in separate applications, as both the first and third posts both state/imply, then there is no amount of trickery that is going to make a signal in one trigger a slot in the other.

steve.bush
20th March 2011, 09:32
Working now!