PDA

View Full Version : Restart aplication with some proprieties from the previous



SamuelNLP
13th March 2013, 14:41
I have a Qt application in which I want to put a restart button, but when it restarts I want it to automatically reconnect with my bluetooth device. here's my code:


void gui::restartapp()
{
int index_combo;

index_combo= ui->devices_infile->currentIndex();

QProcess::startDetached(QApplication::applicationF ilePath());
exit(12);

char *dest;
dest = addr_infile[index_combo];

sock = linkup_directmain(dest, sock);

if (sock != 0 && sock >0)
{
ui->console_1->setText("Connected to:");
ui->console_2->setText(name_infile[index_combo]);
}

else if (sock == -1)
{
ui->console_1->setText("Error connecting");
ui->console_2->setText("Check device status");
}
}

but it only restarts. any idea?

Thank you in advance.

droneone
13th March 2013, 16:20
Having no idea what the rest of your code does, it's kind of impossible to tell you what is wrong.

However, consider a pattern:

(operating)
- Write current state to a file

(starting)
- If a state file exists, read it.
- If the state inside of that file indicates to do something, do it.

SamuelNLP
13th March 2013, 16:44
I got it to work with `QSettings`. I'll publish it later in case someone else needs it. It can work with a file as well as you say.