Results 1 to 5 of 5

Thread: widget doesnt show

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default widget doesnt show

    Hi,

    I am probably missing something very simple, but i cant figure out what it is.

    I have a QMainWIndow MyMainWindow, which shows up just fine. A toolbar holds an action.
    When i click on the toolbar item, the action is triggered correctly, and the slot it is connected to is executed. The slot is a member of MyMainWindow.
    The slot looks like this:


    Qt Code:
    1. bool MyMainWin::myslot()
    2. {
    3. MyWidget c(this);
    4. //c.setWindowModality(Qt::WindowModal);
    5. c.show();
    6. return 1;
    7. }
    To copy to clipboard, switch view to plain text mode 

    As you can see, i just want it to show my custom widget "MyWidget", but it doesnt work.
    It just steps over the c.show() call, but doesnt show anything.

    I am using Qt 4.8.2 with VisualStudio 2008 and the QtAddin. Bot widgets/windows have been designed with the QtDesigner. The custom window shows just fine when i place above code right in main().

    What am i missing?

  2. #2
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widget doesnt show

    You are creating MyWidget on the stack.
    try creating it on the heap.
    Qt Code:
    1. MyWidget *c=new Mywidget(this);
    2. c->show();
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: widget doesnt show

    MyWidget is a local variable, so it's going to be destroyed after exiting out of "myslot" scope.
    You have to create a widget in the heap (e.g. using new).
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Replies: 3
    Last Post: 2nd August 2011, 21:15
  2. How to not show widget
    By gQt in forum Qt Programming
    Replies: 9
    Last Post: 10th June 2010, 19:59
  3. Replies: 10
    Last Post: 29th May 2010, 18:42
  4. QWT doesnt show any windows
    By Cal in forum Qwt
    Replies: 5
    Last Post: 30th June 2009, 17:05
  5. showMaximized doesnt show the canvas
    By Kapil in forum Qt Programming
    Replies: 5
    Last Post: 23rd May 2006, 12:22

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.