我如何檢測是否我的應用程序已經暫停(當有人改變了應用程序),並通過停用我的定時器反應,然後再重新激活它,當我的應用程序變得無法暫停(當有人再次打開我的一半運行應用程序)。下面是我到目前爲止編碼到目前爲止我的應用程序到目前爲止,但它給出了一個錯誤:「'QApplication :: QApplication(const QApplication &)'是私人的」,它說在myapp.cpp第4行的上下文中。請if任何人都可以告訴我我做錯了什麼,將不勝感激。Qt應用程序暫停
這裏是我的main.cpp中的代碼:
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QGraphicsObject>
#include <QTimer>
#include <QVariant>
#include "timecontrol.h"
#include "scorecontrol.h"
#include "Retry.h"
#include <QEvent>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewer.setMainQmlFile(QLatin1String("qml/Raker/main.qml"));
viewer.showExpanded();
QObject *rootObject = viewer.rootObject();
QTimer *timmer = new QTimer;
timmer->setInterval(1000);
TimeControl *timcon = new TimeControl;
scorecontrol *scorer = new scorecontrol;
Retry *probeer = new Retry;
QObject::connect(timmer, SIGNAL(timeout()), timcon, SLOT(updateTime()));
QObject::connect(timcon, SIGNAL(setTime(QVariant)), rootObject, SLOT(setTime(QVariant)));
QObject::connect(rootObject, SIGNAL(blockClicked(int, int)), scorer, SLOT(checkRight(int, int)));
QObject::connect(scorer, SIGNAL(setScore(QVariant)), rootObject, SLOT(setScore(QVariant)));
QObject::connect(scorer, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(rootObject, SIGNAL(start()), probeer, SLOT(Reetry()));
QObject::connect(probeer, SIGNAL(start()), timmer, SLOT(start()));
QObject::connect(probeer, SIGNAL(start(int)), scorer, SLOT(randomNum(int)));
QObject::connect(probeer, SIGNAL(sReset()), timcon, SLOT(reset()));
QObject::connect(probeer, SIGNAL(tReset()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(timeOut()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(timcon, SIGNAL(changeFinal()), scorer, SLOT(changeFinal()));
QObject::connect(scorer, SIGNAL(setFinal(QVariant)), rootObject, SLOT(setFinal(QVariant)));
return app.exec();
}
myApp.h:
#ifndef MYAPP_H
#define MYAPP_H
#include <QApplication>
#include <QObject>
class MyApp : public QApplication
{
public:
MyApp(QApplication &app);
protected:
bool eventFilter(QObject *obj, QEvent *event);
};
#endif // MYAPP_H
MyApp.cpp中:
#include "myapp.h"
#include <QEvent>
MyApp::MyApp(QApplication &app) : QApplication(app)
{
installEventFilter(this);
}
bool MyApp::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ApplicationDeactivate)
{
}
if (event->type() == QEvent::ApplicationDeactivate)
{
}
else
{
return false;
}
}
你問如何實現在QT一[看門狗定時器(http://en.wikipedia.org/wiki/Watchdog_timer)? – 2011-10-24 04:31:10