Connect SLOTS in QApplication problem
Hello,
I am trying to inherit QApplication in my code but unfortulately i am unable to connect with SLOTS,
I have commented the Q_OBJECT macro coz when i uncomment that macro it creates vtable problem to me.
Any idea about this problem please help.
.h file
Code:
#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <QObject>
#include <QEvent>
#include <QTimer>
#include <QDebug>
{
// Q_OBJECT
public:
explicit InactivityWatcher(int &argc, char *argv[]);
public:
protected slots:
void appIdleForFiveSecs();
virtual bool event
(QEvent * e
);
};
.cpp file
Code:
InactivityWatcher::InactivityWatcher(int &argc, char *argv[]):
{
// 3600000 => 30 minutes
m_timer.setInterval(10000);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(appIdleForFiveSecs()), Qt::UniqueConnection);
m_timer.start();
}
void InactivityWatcher::appIdleForFiveSecs()
{
qDebug() << "Inactive ";
m_timer.stop();
}
{
if (event
->type
() == QEvent::MouseMove || event
->type
() == QEvent::KeyPress) { qDebug() << "Active";
m_timer.stop(); // reset timer
m_timer.start();
}
}
bool InactivityWatcher
::event(QEvent *e
) {
}
Re: Connect SLOTS in QApplication problem
signals & slots will work only if Q_OBJECT macro is included. So you need to uncomment Q_OBJECT to make your connection work.
Re: Connect SLOTS in QApplication problem
Thanks but when i uncomment Q_OBJECT macro i have got vtable reference errors.
Code:
./build\objects\main.o:main.cpp:(.text+0x122a): undefined reference to `vtable for InactivityWatcher'
./build\objects\main.o:main.cpp:(.text+0x1add): undefined reference to `vtable for InactivityWatcher'
./build\objects\inactivitywatcher.o:inactivitywatcher.cpp:(.text+0x2c): undefined reference to `vtable for InactivityWatcher'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [build\product\TouchDox.exe] Error 1
mingw32-make.exe: *** [release] Error 2
please tell me if you have any idea about this problem?
Re: Connect SLOTS in QApplication problem
Try "clean project", then run qmake to rebuild and run.
If your are in doubt if your moc files are deleted properly, manually delete projectName.pro.user file, debug & release folders and run qmake.
Re: Connect SLOTS in QApplication problem
Thanks it works... :P
i feel like dumb :rolleyes:
Re: Connect SLOTS in QApplication problem
Quote:
virtual bool notify(QObject *receiver, QEvent *event);
virtual bool event (QEvent * e);
You don't intend for these to be slots, do you? Why are they included in the slots declaration of your class?
Re: Connect SLOTS in QApplication problem
I've had the same problem today I've solved implementing explicitly a destructor... an empty one does the trick too!
Then the 'vtable' it was defined again... whatever it is!
I have really the G++ errors they simply means nothing...
Re: Connect SLOTS in QApplication problem
The vtable error is typical artifact when a Q_OBJECT marker is added to a header that did not contain it at the time the header was added to the project.
All headers with that marker need to be processed by MOC, when a header is added to the .pro file then it is checked for whether this is necessary.
If the header at this time does not contain the marker yet, no MOC rule is generated. Adding the marker afterwards thus leaves the file only temporarily processed.
Re-running qmake (either manually or though QtCreator's build menu) will always fix that.
Generally it is most easily avoided by always putting the Q_OBJECT marker into classes directly or indirectly derived from QObject.
Cheers,
_