Results 1 to 5 of 5

Thread: Problem with GUIs

  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with GUIs

    I have a class derived from QGraphicsView that creates a GUI only if created by the main.
    So, this works:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. scene.setSceneRect(0, 0, 1024, 768);
    6. scene.setBackgroundBrush(QColor::fromRgb(47, 51, 47));
    7.  
    8. gui view(&scene);
    9. view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    10. view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    11. view.setWindowFlags(Qt::FramelessWindowHint) ;
    12. view.setCacheMode(QGraphicsView::CacheBackground);
    13. view.setDragMode(QGraphicsView::NoDrag);
    14. view.setFixedSize(1024, 768);
    15. view.show();
    16.  
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    And this doesn't work:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. Starter s;
    5. return a.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class Starter : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Starter();
    7. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Starter::Starter()
    2. {
    3. s.setSceneRect(0, 0, 1024, 768);
    4. s.setBackgroundBrush(QColor::fromRgb(47, 51, 47));
    5.  
    6. gui view(&s);
    7.  
    8. view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    9. view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    10. view.setWindowFlags(Qt::FramelessWindowHint) ;
    11. view.setCacheMode(QGraphicsView::CacheBackground);
    12. view.setDragMode(QGraphicsView::NoDrag);
    13. view.setFixedSize(1024, 768);
    14. view.show();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Why ?

    The main problem is that I need a GUI with an empty constructor as my main application will load a plugin (the GUI) that will create a GUI based on a QGraphicsScene.
    So the Starter could create the QGraphicsScene and pass it to the gui class, but it doesn't work.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with GUIs

    IN the constructor of Starter you declare s into the
    stack.
    When the constructor exits, this instance is destroyed and
    then your scene doesn't exists.

    Try declaring s as member of Starter
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with GUIs

    Thanks but no, doesn't work

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with GUIs

    Sorry,

    also the gui instance is destroyed when Starter constructor exits.
    Then, also the gui instance must be a Starter Member
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with GUIs

    Quote Originally Posted by mcosta View Post
    Sorry,

    also the gui instance is destroyed when Starter constructor exits.
    Then, also the gui instance must be a Starter Member
    Yes of course, I've seen it and I've just corrected it and it works.

    Thanks a lot

Similar Threads

  1. Problem with QAbstractListModel
    By eekhoorn12 in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2009, 14:26
  2. Replies: 1
    Last Post: 23rd April 2009, 09:05
  3. Replies: 19
    Last Post: 3rd April 2009, 23:17
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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.