PDA

View Full Version : Connect question...



McCall
20th June 2007, 17:08
Hi Folks,

I am having a problem getting messages between my classes. My basic program structure is like this: Main creates a MyApp::QApplication, MyApp creates a MyWindow::QMainWindow. In MyApp I have an About().

My Problem is I don't know how to connect the QAction created for the menu entry in MyWindow to the MyApp::About()? I have been trying to do something like this:

connect(AboutAction,SIGNAL(triggered()),MyApp,SLOT (about()));

But that obvisouly won't work as MyWindow doesn't know about MyApp :)

Can anyone help me please?

Thanks

McCall

jpn
20th June 2007, 17:18
Try QApplication::instance() (or qApp) in place of MyApp in the connect statement.

McCall
20th June 2007, 17:44
Thanks for the quick reply, I had looked at the examples and tried qApp, but hadn't included the QApplication header so the build failed :) I have now added:

#include <QApplication>

and change my connect to this:

connect(AboutAction,SIGNAL(triggered()),QApplicati on::instance(),SLOT(About()));

My method is declared like this:

private slots:
void About();

and my method is this:

void PlaygroundApplication::About()
{

QMessageBox::about(mainPlaygroundWindow, tr("About SDI"),
tr("The <b>SDI</b> example demonstrates how to write single "
"document interface applications using Qt."));
}

Yet, I never get to About().

Can you see something that I am doing wrong?

jpn
20th June 2007, 17:49
Does PlaygroundApplication declaration contain Q_OBJECT (http://doc.trolltech.com/4.3/qobject.html#Q_OBJECT) macro?

Edit: Oh, and in case it doesn't, make sure the corresponding header file is listed and .pro file and qmake is re-run after adding the macro.

McCall
20th June 2007, 18:19
Thanks!

Q_OBJECT and a qmake clean did the trick!