PDA

View Full Version : main.moc



talk2amulya
19th February 2009, 06:50
how to create a main.moc file??

spirit
19th February 2009, 06:53
you need to create object deriven from QObject and then regenerate project, i.e. call qmake.

talk2amulya
19th February 2009, 07:04
hi,

could u please provide me with an example??

Thanks

spirit
19th February 2009, 07:07
yesterday example :D


#include <QTimer>
#include <QApplication>

class MyProcessEventDispatcher: public QObject
{
Q_OBJECT

public:
MyProcessEventDispatcher(QObject *parent = 0)
: QObject (parent)
{
connect(&m_timer, SIGNAL(timeout()), SLOT(updateEvents()));
m_timer.setInterval(100);
m_timer.start();
}

private slots:
void updateEvents()
{
m_timer.start();
qApp->processEvents();
}

private:
QTimer m_timer;
};
#include "main.moc"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyProcessEventDispatcher mpee;
//...
return app.exec();
}

add this code to yours main.cpp, clean your project and then call qmake. now, when you start compilation main.com will be generated.

jpn
19th February 2009, 07:07
// main.cpp

class Object : public QObject
{
// no Q_OBJECT macro here
};

int main()
{
}

#include "main.moc" // moc file included by hand, but there is nothing for moc to generate


vs.



// main.cpp

class Object : public QObject
{
Q_OBJECT // macro exists
};

int main()
{
}

#include "main.moc" // moc file included by hand, moc generates meta object code for "Object"

talk2amulya
19th February 2009, 07:26
hi guys,

thanks for clearing that up..i have another query..i m trying smth like this from main.cpp


QTimer timer;
bool isConnect = QObject::connect(&timer, SIGNAL(timeout()), qApp, SLOT(processEvents()));
timer.start(100);

now this, wont connect cuz processEvents() isnt actually a slot..is there any possible way i can call qApp->processEvents() from main.cpp on timeout of a timer..it would be great help if u can help me solve this..

thanks in advance!

spirit
19th February 2009, 07:28
I've posted an example how to do this. why you can't use it? it solves you problem. :)

talk2amulya
19th February 2009, 07:35
buddy, i tried that..in ur case, updateEvents() was called only once..no more than that..so i just wanted to try this as the last option..or i'll just give this problem to sm1 else..

spirit
19th February 2009, 07:38
in your case (which you try to achive) you will have the same behavior, because yours "have"-comp block event loop! so, there is no difference between your code (what you try to achive) and my!