Results 1 to 5 of 5

Thread: Qt in other class

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt in other class

    I wish to write a totaly simple C++ class. It should contain a pointer to a QMainWidget (or another suitable Qt object) and if a certain bool variable is set to false the pointer should be 0 or else it should point to a qtobject that contains three buttons and a big area where I can draw stuff.

    Like this
    Qt Code:
    1. class Box{
    2. private:
    3. SomeQtclass* theQtObject;
    4. bool use_gui;
    5. void drawstuff(){if (use_gui) /*do stuff*/}
    6. void do_random_thing_not_directly_affecting_the_gui();
    7. };
    To copy to clipboard, switch view to plain text mode 

    In the main application I would then have
    Qt Code:
    1. int main()
    2. {
    3. Box mybox;
    4. cin>>mybox.use_gui;
    5. while (true){
    6. mybox.do_random_thing_not_directly_affecting_the_gui();
    7. mybox.drawstuff();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    The Box class should be a kind of class that could be included in many other programs, like std::string.

    How do I write this kind of code? I need some kind of QApplication, right? Where do I put it?
    Anyone with idas, please speak up!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt in other class

    But what is exactly your problem? Based on the number of your posts and the forum you post in I take it that you should know where to create a QApplication object...
    Last edited by wysota; 8th April 2006 at 22:45.

  3. #3
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in other class

    But the thing is, I don't want to give up the controll to QApplication::exec(). I can't run it and get back to the other code I was running before that? That is the problem.

    Don't let the number of questions fool you. It might be a sign of a REAL newbee.

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt in other class

    Quote Originally Posted by Morea
    But the thing is, I don't want to give up the controll to QApplication::exec(). I can't run it and get back to the other code I was running before that? That is the problem.

    Don't let the number of questions fool you. It might be a sign of a REAL newbee.
    Just do it!
    Basically, the whole QtCore module is accessible (containers and so on) without any need of QApplication::exec() but if you want piece of GUI you'll need to give up the control and rely on the event loop...
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt in other class

    If you want to run some code in parallel to operating on a GUI, you might consider running it in a separate thread or as a timeout slot for a QTimer object.

Similar Threads

  1. Replies: 3
    Last Post: 27th December 2008, 19:34
  2. class in the class
    By baray98 in forum General Programming
    Replies: 2
    Last Post: 23rd July 2008, 07:01
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.