Results 1 to 5 of 5

Thread: How to display widget in calling method, called from main

Hybrid View

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

    Default Re: How to display widget in calling method, called from main

    Maybe it's just the problem with the example, but main() in the first post is not calling newWindow()?

    Here are a couple of examples. Two windows appear with self-explanatory titles:
    Qt Code:
    1. // main.cpp
    2. #include <QApplication>
    3. #include <QMainWindow>
    4.  
    5. void newWindow()
    6. {
    7. QMainWindow* window = new QMainWindow;
    8. window->setWindowTitle("Created in newWindow()");
    9. window->setAttribute(Qt::WA_DeleteOnClose);
    10. window->show();
    11. }
    12.  
    13. QMainWindow* createWindow()
    14. {
    15. QMainWindow* window = new QMainWindow;
    16. window->setWindowTitle("Created in createWindow()");
    17. window->setAttribute(Qt::WA_DeleteOnClose);
    18. return window;
    19. }
    20.  
    21. int main(int argc, char* argv[])
    22. {
    23. QApplication a(argc, argv);
    24. newWindow();
    25. QMainWindow* window = createWindow();
    26. window->show();
    27. return a.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:

    kaydknight (10th March 2007)

  3. #2
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display widget in calling method, called from main

    Opps! Silly me, I did not include newWindow in the first post.

    Emmm, anyway, as per previous situation, I did call method newWindow from main, Just that it was still destroyed after returning to main.

    But you know what's weird? I tried running your original solution again, and this time it worked!!! I don't know why. I suspect it must have something to do with not cleaning my previous built project solution (I use vc2005 express) and kept some of the old settings, or something else maybe

    Well, the example you showed now works! I'm also able to add other widgets into the main widget. Thank you very much!
    Last edited by kaydknight; 10th March 2007 at 18:34.

Similar Threads

  1. Display multiple Images in a widget
    By jeetu_happy in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2007, 11:24
  2. QTabWidget Placement and Display
    By mclark in forum Newbie
    Replies: 1
    Last Post: 16th January 2007, 20:34
  3. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35
  4. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 12:07
  5. Replies: 3
    Last Post: 12th April 2006, 08:20

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.