PDA

View Full Version : Get (custom) return value of modal dialog?



Terreox
19th February 2012, 13:58
Hi
i have a problem with interaction between a QDialog and a QMainWindow.

On startup my program shows a QMainWindow (ControlPanel). On this Controlpanel there are serveral menubuttons. One of them opens a QDialog (NewIncident). In NewIncident the user can type some information about an incident (i write a program for our local firedepartment by the way^^). If the user clicks the alerting button, NewIncident creates an instance of an Incident object which contains every information typed in by the user(e.g. Location, Caller, Phonenumber etc.). My problem is how do i return the instance to Controlpanel? ControlPanel needs this instance to work with it (list of current incident, history of incidents,...).

Here is some code:



void ControlPanel::on_btNewIncident_clicked()
{
NewIncident *newincident = new NewIncident(this);
newincident->exec();
Incident incSheet = newincident->getIncSheet();
qDebug() << incSheet.acceptor;
}
I only used a qDebug() to see if anything is available in incSheet. But it outputs "" :(

I dont know how to go further -.- I talked to a friend who programs a lot (unfortunately not with Qt) but he could not help me out.
How can i get this to work?

Greetz

p.s.: would be nice if newincident could stay a modal dialog. I dont want that the user can interact with other windows of the program while NewIncident is there.

Terreox
19th February 2012, 16:20
Ok i solved this problem on my own.
I just changed some things:



NewIncident *newincident = new NewIncident(this);
if(!newincident->exec()){
incSheet = newincident->getIncSheet();
refresh(incSheet);
}


I realised that exec() returns 0 in my program so i have to catch !newincident->exec() of course -.-'
Then i initialized a class member variable(incSheet) of type Incident with the return value of getIncSheet() <- returns all values i need
refresh() is only a function to refresh some element on ControlPanel.