Thanks to all who responded to me. You have given me lots of ideas and helped me a lot.
For example I did not know that custom slot classes should be in the *.h file with mingw compiler. I had absolutely no idea that you could include "filename.moc" file if your custom class is in the *.cpp file. I did not get this to work yet but it it good to know that such an option exists. Thanks for pointing out that I had the slot connected all wrong, too.
So I guess I have to start using *.h files for classes and I will. But at the same time I'm very curious if my compiler has some kind of a problem. I'd appreciate it a lot if somone was able to run the below code through their compiler and let me know what kind of error messages other compilers gave. Or perhaps it'll work with other compilers no problem.
Thanks a lot.
Here's the code:
#include <QApplication>
#include <QPushButton>
#include <QHBoxLayout>
using namespace std;
{
Q_OBJECT
public:
public slots:
void myExitSlot();
};
void MyExit::myExitSlot()
{
qApp->quit();
}
{
}
int main(int argc, char *argv[])
{
mainLayout->addWidget(b1);
QObject::connect(b1,
SIGNAL(clicked
()),
&MyExit,
SLOT(myExitSlot
()));
window.show();
return a.exec();
}
#include <QApplication>
#include <QPushButton>
#include <QHBoxLayout>
using namespace std;
class MyExit : public QObject
{
Q_OBJECT
public:
MyExit (QObject *parent = 0);
public slots:
void myExitSlot();
};
void MyExit::myExitSlot()
{
qApp->quit();
}
MyExit::MyExit(QObject *parent):QObject(parent)
{
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;
QHBoxLayout* mainLayout = new QHBoxLayout(&window);
QPushButton *b1 = new QPushButton("Exit");
mainLayout->addWidget(b1);
QObject::connect(b1, SIGNAL(clicked()), &MyExit, SLOT(myExitSlot()));
window.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks