Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: want to hide mainwindow at program start up

  1. #21
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: want to hide mainwindow at program start up

    Quote Originally Posted by masuk View Post
    but i need further better solution
    there you go:

    Quote Originally Posted by FelixB View Post
    override showEvent for your MainWindow and check your condition there...

  2. #22
    Join Date
    Oct 2009
    Location
    Texas
    Posts
    15
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: want to hide mainwindow at program start up

    Qt Code:
    1. if (condition)
    2. m = new dlgMain1();
    3. else
    4. m = new dlgMain2();
    5.  
    6. m->show();
    To copy to clipboard, switch view to plain text mode 

  3. #23
    Join Date
    Nov 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: want to hide mainwindow at program start up

    This one had been biting me on the hiney for some time, so I thought I'd share what I went with.

    If you do a "hide()" in the ctor, and then yer main looks like:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    what you have done is told it to hide(), and then show(). That won't work. I made a public variable in my subclassed QMainWindow, so that I do something similar to:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8.  
    9. if (w.bRunHidden)
    10. w.hide();
    11. else
    12. w.show();
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    It also doesn't run right without the hide(). I do realize that this doesn't address your problem of showing the other form. If the parent is not visible, neither will the child be. Thus, you would have to make a parentless form, which makes sense on Windows, in any event. It will create its own taskbar entry. You will have to keep up with it's hiding and showing, however. If a user makes the MainWindow visible, and then minimizes it, your child form may need to be hidden too; and restore when the parent is restored. Depending on what you are doing, you might be taking the wrong approach. I made a serial number screen for a prog I'm working on; and simply created it, showed it and dealt with the response in the main, before I ever created the MainWindow. Also, I suppose making that a function is better form.
    Last edited by CodeLurker; 26th November 2015 at 20:44.

Similar Threads

  1. how to start a program in the background
    By JustinTerpstra in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2010, 23:51
  2. Start program with right button
    By Pablo128 in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2010, 13:03
  3. Can't start a qt-program on embedded linux
    By Tschounes in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th June 2010, 23:39
  4. add a program to start menu
    By kpmsivachand in forum KDE Forum
    Replies: 1
    Last Post: 26th January 2009, 20:19
  5. How to hide mainwindow at program start up
    By palmer in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2008, 14:35

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.