Results 1 to 4 of 4

Thread: show/hide QMainWindow from another QMainWindow

  1. #1
    Join Date
    May 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default show/hide QMainWindow from another QMainWindow

    Hello.

    In my program I got 2 QMainWindows. How can I show/hide my second Window from the first?
    In the constructor of the second Window I got "this->show();" and it does show without a problem.
    But when I create a slot in the first Window to run this as well ( this->show(); ) in another function in my second Window class it says: 'this' is unavailable for static member functions.
    (so, in a slot of my first window class I try to access a static function in my second Window class)
    I hope I made myself clear. This function I'm trying to access is static, but I dont think I should keep it that way.

    I can type my code if its easier for you.

    For the record, this second window is basically a widget, a label. I just want it aside from my (true) main window.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: show/hide QMainWindow from another QMainWindow

    If you want two windows in your application, then first you will need to create two instance (objects) of windows (widgets), only then you can show them. Using static functions to show is ok as long as you create the object of the second widget.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    May 2013
    Posts
    10
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: show/hide QMainWindow from another QMainWindow

    I do create it, but i still haven't figured out a way to do it. I'll keep digging.

    No matter how I try it, there's always a conflict between static or non static members.
    In My main() I instanciate both mainWindows. All I want is to be able to show/hide one from the other.
    Last edited by PauloF91; 14th June 2013 at 11:46.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: show/hide QMainWindow from another QMainWindow

    Forget about static members when you are dealing with two instances.

    You either pass a pointer of one window to the other and then call methods on it, or you have one window emit signals and connect that to the other window's slots.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 13th November 2011, 09:12
  2. Replies: 0
    Last Post: 22nd September 2011, 11:31
  3. Replies: 2
    Last Post: 29th June 2011, 16:45
  4. Replies: 0
    Last Post: 17th November 2010, 18:07
  5. Hide QMainWindow without removing taskbar icon?
    By bigchiller in forum Qt Programming
    Replies: 5
    Last Post: 15th March 2009, 23:54

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.