Search code examples
c++qt

Restart application with some proprieties from the previous


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:

// Restart app
void gui::restartapp()
{
    int index_combo;

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

    QProcess::startDetached(QApplication::applicationFilePath());
    QCoreApplication::exit()

    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?


Solution

  • // Restart app
    void gui::restartapp()
    {
        close_s(sock);
    
        last_session = true;
    
        settings.setValue("deviceid", ui->devices_infile->currentIndex());
        settings.setValue("lastsession", last_session);
    
        QProcess::startDetached(QApplication::applicationFilePath());
        QCoreApplication::exit();
    }