在网上搜了下,基本都是那一个答案,不太明白,望高手指点
------解决方案--------------------
先启动和自己同样的进程,再关闭自己。
如果你使用QT,可以像下面那样做:
- C/C++ code
#include <QtGui>class Temp : public QWidget { Q_OBJECT private: QLabel *label; QPushButton *button;public: Temp(QWidget *parent = 0); public slots: void ClickedButton();}; Temp::Temp(QWidget *parent) : QWidget(parent) { button = new QPushButton("restart", this); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(button); setLayout(layout); move(200, 200); connect(button, SIGNAL(clicked()), this, SLOT(ClickedButton()));} void Temp::ClickedButton(){ QProcess *p = new QProcess(this); QString str = QApplication::applicationFilePath(); p->startDetached(str); close();}#include "main.moc" int main(int argc, char *argv[]) { QApplication app(argc, argv); Temp *temp = new Temp; temp->show(); return app.exec(); }