2013-03-13 89 views
0

我有一個Qt應用程序,我想在其中重新啓動按鈕,但是當它重新啓動時,我希望它自動重新連接我的藍牙設備。這裏是我的代碼:重新啓動應用程序與以前的一些東西

// 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"); 
    } 
} 

但它只是重新啓動。任何想法?

預先感謝您。

更新:

我得到它的工作。我會稍後發佈它,以防別人需要它。

+0

'exit(12)'是什麼?''做? – 2013-03-13 15:00:42

+0

對不起。它應該是0.我的壞。 – SamuelNLP 2013-03-13 15:03:24

+0

所以後面的代碼'exit(0);'永遠不會執行? – 2013-03-13 15:04:47

回答

1
// 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(); 
} 
1

QCoreApplication::exit()只告訴應用程序退出。 exit()之後的代碼在與調用restartapp()相同的應用程序實例中執行。應用程序的另一個實例是簡單地啓動。 您應該將設置存儲在某個地方,然後在應用程序啓動時加載它們。

+0

是的,我現在正在處理它。 :) – SamuelNLP 2013-03-13 16:16:46

+0

我得到它的工作。我會稍後發佈它,以防別人需要它。 – SamuelNLP 2013-03-13 16:40:50