LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to close the main window in Qt creator without exiting the program? (https://www.linuxquestions.org/questions/programming-9/how-to-close-the-main-window-in-qt-creator-without-exiting-the-program-4175417872/)

darkstarbyte 07-20-2012 07:12 PM

How to close the main window in Qt creator without exiting the program?
 
I have been googling this for the past week, and I can't find how to close the main window in Qt creator without closing the program. I tried to go as far as I could without asking for help, but this one just go me.

EDIT:
What I want to do is, create a main window that has options that opens up other windows, then close that main window without exiting the program.

darkstarbyte 07-22-2012 10:45 PM

I guess not very many people use Qt creator to code GUIs.

saman_artorious 07-24-2012 01:10 PM

Quote:

Originally Posted by darkstarbyte (Post 4735525)
I guess not very many people use Qt creator to code GUIs.

try hiding the mainwindow. You somehow cannot close it as it is the application only active window in the main program.
so, once it is returned, the main program returns.

darkstarbyte 07-29-2012 03:44 AM

Oh, with the hide function. (If I am naming the right one.)

Thanks for your response, I was starting to think I was a very lonely coder.

saman_artorious 07-31-2012 03:32 PM

Quote:

Originally Posted by darkstarbyte (Post 4740432)
Oh, with the hide function. (If I am naming the right one.)

Thanks for your response, I was starting to think I was a very lonely coder.

!!! why lonely! it seems you are not familiar with the qt center forum: http://www.qtcentre.org

darkstarbyte 08-02-2012 11:36 AM

thanks, it denied me a couple of times through the image verification. Those are getting harder to pass than learning to write programs.

saman_artorious 08-04-2012 03:22 AM

Quote:

Originally Posted by darkstarbyte (Post 4740432)
Oh, with the hide function. (If I am naming the right one.)

Thanks for your response, I was starting to think I was a very lonely coder.

I got what you were looking for. I have two main windows in my program. you may have created a variable of the second window in the first windows header file and initiated it in the first windows constructor. So, set its parent to 0. if you do this, you can close the first window then.

here's a sample:

first window header
Code:

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    SettingsWindow *settings;

first window constructor:
Code:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    settings = new SettingsWindow(cfg,0);

second (settings) window constructor:
Code:

SettingsWindow::SettingsWindow(ConfigSource &src, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::SettingsWindow)
{

you may not worry about the first parameter of settings window, COnfigSource, I mean, I have added this myself. you simply have one parameter which is QWidget *parent. set it to 0.

(problem solved ;))

darkstarbyte 08-09-2012 02:46 AM

I will leave this unsolved, just in case more problems arise about this subject.

EDIT:
Thanks for your response saman_artorious


All times are GMT -5. The time now is 03:41 AM.