PDA

View Full Version : Open back a closed frame?



danoc93
19th January 2012, 17:37
Escenario:

1. Main window opens
2. I click a pushbutton to go the help window
3. Help window opens, main window closes


That's fine... but when I add a pushbutton to the help window to go the main window again, I get a compilation error... I use the exact same code I use to open a new frame... but I don't know what is happening... apparently it has something to do with the fact that the main window is already declared or something...

wysota
19th January 2012, 21:22
We don't know what is happening either. You have the advantage of having actually seen the error.

danoc93
19th January 2012, 23:40
Well... lets say I have:

mainwindow.h
mainwindow.cpp
aboutwindow.h
aboutwindow.cpp

In order for mainwindow to open aboutwindow using a pushbutton I have to do this:

In mainwindow.h, I do the following modifications.

#include aboutwindow.h //Include the header of the window I wanna open

on public slots:

void openAboutWindow(); //Declare a function to open the window

on private:
AboutWindow * windowAbout; //I declare a var for the window

on private slots:
void on_buttonabout_clicked(); //Thats the function to call when I click on the push button

And then on mainwindow.cpp I add the following code:


void MainWindow :: on_buttonabout_clicked() //This is executed once I click the button
{
openAboutWindow();

}

void MainWindow :: openAboutWindow() //This is called by the previous function
{n
close(); //This closes the current window
windowAbout = new AboutWindow(this);
windowAbout->show(); //This shows the "about" window
}



----


That works perfectly to call a new window that I haven't opened before.... But once I do that, let's say I want to go back to the main window... so in the aboutwindow.ui I add a new push button, and I do the exact same code, except this time goes from aboutwindow to mainwindow... but it doesn't work... gives me a compilation error:

"ISO C++ forbids the declaration of MainWindow with no type", that is the on private line I added...

wysota
20th January 2012, 00:36
You probably end up with:

file1.h: #include "file2.h"
file2.h: #include "file1.h"

You have to sort out the circular dependency. Forward declarations and refactoring are common solutions to the problem.

danoc93
20th January 2012, 00:55
:D and how could I do that? I'm just starting with QT and C++... just an idea could be useful, thanks in advance.

wysota
20th January 2012, 01:04
I have already given you two ideas. Type them into your favourite web search engine and see what pops out.