void QApplication::alert(QWidget * widget, int msec = 0)
如果窗口不是活动窗口,则会向窗口显示一个警告。警报会显示msec 毫秒。
如果毫秒为零,闪烁一段时间后会停止,任务栏图标会一直亮着。
widget.h
- #ifndef WIDGET_H
- #define WIDGET_H
- #include <QWidget>
- #include <QTimer>
- #include <QTime>
- namespace Ui {
- class Widget;
- }
- class Widget : public QWidget
- {
- Q_OBJECT
- public:
- explicit Widget(QWidget *parent = 0);
- ~Widget();
- void setms(int m);
- public slots:
- void start();
- private:
- Ui::Widget *ui;
- int ms;
- QTimer *timer;
- };
- #endif // WIDGET_H
widget.cpp
- #include "widget.h"
- #include "ui_widget.h"
- Widget::Widget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::Widget)
- {
- ui->setupUi(this);
- timer = new QTimer();
- timer->setInterval(1000);
- timer->start();
- connect(timer, SIGNAL(timeout()), this, SLOT(start()));
- }
- Widget::~Widget()
- {
- delete ui;
- }
- void Widget::start()
- {
- QApplication::alert(this, ms);
- }
- void Widget::setms(int m)
- {
- ms=m;
- }
main.cpp
- #include "widget.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Widget w;
- w.setms(1000);
- w.show();
- return a.exec();
- }
http://blog.chinaunix.net/uid-29994589-id-5207150.html