Results 1 to 9 of 9

Thread: main.moc

  1. #1
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 66 Times in 62 Posts

    Default main.moc

    how to create a main.moc file??

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: main.moc

    you need to create object deriven from QObject and then regenerate project, i.e. call qmake.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 66 Times in 62 Posts

    Default Re: main.moc

    hi,

    could u please provide me with an example??

    Thanks

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: main.moc

    yesterday example
    Qt Code:
    1. #include <QTimer>
    2. #include <QApplication>
    3.  
    4. class MyProcessEventDispatcher: public QObject
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. MyProcessEventDispatcher(QObject *parent = 0)
    10. : QObject (parent)
    11. {
    12. connect(&m_timer, SIGNAL(timeout()), SLOT(updateEvents()));
    13. m_timer.setInterval(100);
    14. m_timer.start();
    15. }
    16.  
    17. private slots:
    18. void updateEvents()
    19. {
    20. m_timer.start();
    21. qApp->processEvents();
    22. }
    23.  
    24. private:
    25. QTimer m_timer;
    26. };
    27. #include "main.moc"
    28. int main(int argc, char **argv)
    29. {
    30. QApplication app(argc, argv);
    31. MyProcessEventDispatcher mpee;
    32. //...
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 
    add this code to yours main.cpp, clean your project and then call qmake. now, when you start compilation main.com will be generated.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: main.moc

    Qt Code:
    1. // main.cpp
    2.  
    3. class Object : public QObject
    4. {
    5. // no Q_OBJECT macro here
    6. };
    7.  
    8. int main()
    9. {
    10. }
    11.  
    12. #include "main.moc" // moc file included by hand, but there is nothing for moc to generate
    To copy to clipboard, switch view to plain text mode 

    vs.

    Qt Code:
    1. // main.cpp
    2.  
    3. class Object : public QObject
    4. {
    5. Q_OBJECT // macro exists
    6. };
    7.  
    8. int main()
    9. {
    10. }
    11.  
    12. #include "main.moc" // moc file included by hand, moc generates meta object code for "Object"
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 66 Times in 62 Posts

    Default Re: main.moc

    hi guys,

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

    Qt Code:
    1. QTimer timer;
    2. bool isConnect = QObject::connect(&timer, SIGNAL(timeout()), qApp, SLOT(processEvents()));
    3. timer.start(100);
    To copy to clipboard, switch view to plain text mode 

    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!

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: main.moc

    I've posted an example how to do this. why you can't use it? it solves you problem.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 66 Times in 62 Posts

    Default Re: main.moc

    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..

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: main.moc

    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!
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.