-
Connect question...
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
-
Re: Connect question...
Try QApplication::instance() (or qApp) in place of MyApp in the connect statement.
-
Re: Connect question...
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?
-
Re: Connect question...
Does PlaygroundApplication declaration contain 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.
-
Re: Connect question...
Thanks!
Q_OBJECT and a qmake clean did the trick!