MainWindow
::MainWindow(QWidget *parent
) :ui(new Ui::MainWindow)
{
ui->setupUi(this);
worker = new InventoryWorker; // parent is forbidden here
worker->moveToThread(invThread);
connect(ui->start,SIGNAL(clicked()),
invThread, SIGNAL(startTimer())); // add slot startTimer in InventoryWorker
invThread->start();
}
MainWindow::~MainWindow() {
worker->deleteLater();
invThread->terminate();
invThread->waitFor(3000);
}
{
handle = h;
list = lst;
list->connect(timer,SIGNAL(timeout()),SLOT(clear()));
connect(timer,SIGNAL(timeout()),list,SLOT(clear()));
timer->setSingleShot(false);
}
InventoryWorker::startTimer() {
timer->start(1500);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
invThread = new QThread(this);
worker = new InventoryWorker; // parent is forbidden here
worker->moveToThread(invThread);
connect(ui->start,SIGNAL(clicked()),
invThread, SIGNAL(startTimer())); // add slot startTimer in InventoryWorker
invThread->start();
}
MainWindow::~MainWindow() {
worker->deleteLater();
invThread->terminate();
invThread->waitFor(3000);
}
InventoryWorker::InventoryWorker(QObject *parent, int h, QListWidget * lst) : QObject(parent)
{
handle = h;
list = lst;
timer = new QTimer(this);
list->connect(timer,SIGNAL(timeout()),SLOT(clear()));
connect(timer,SIGNAL(timeout()),list,SLOT(clear()));
timer->setSingleShot(false);
}
InventoryWorker::startTimer() {
timer->start(1500);
}
To copy to clipboard, switch view to plain text mode
Bookmarks