我正在尝试在工作线程中启动倒计时器,当用户单击PushButton时。计时器开始倒计时的值取决于GUI中所选的半径按钮。我使用SignalMapper将计时器的起始值作为参数传递。但是,当我尝试编译我的代码时,会出现以下错误:
static assertion failed: Signal and slot arguments are not compatible
我的代码:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
connect(ui->btnTakeSnap, SIGNAL(clicked()), this, SLOT(startTimerWorker()) );
}
void MainWindow::startTimerWorker()
{
myThread = new QThread(this);
workerObj = new workerTimer();
QSignalMapper* signalMapper = new QSignalMapper (this) ;
connect(myThread, &QThread::started, signalMapper, SLOT(map()) );
if(ui->rdBtntimer1s->isChecked())
{signalMapper -> setMapping (myThread, 1000) ; }
if(ui->rdBtntimer3s->isChecked())
{signalMapper -> setMapping (myThread, 3000) ; }
if(ui->rdBtntimer5s->isChecked())
{signalMapper -> setMapping (myThread, 5000) ;}
connect(signalMapper, SIGNAL(mapped(int)), workerObj, SLOT(&workerTimer::countDown(int)));
workerObj->moveToThread(myThread);
myThread->start();
}
class workerTimer : public QObject
{
Q_OBJECT
public:
explicit workerTimer(QObject *parent = nullptr);
signals:
public slots:
void countDown(int selectedTimer);
};
有人能解释一下我可能做错了什么吗?
谢谢
ui->setupUi(this);
,这是打字错误吗? - eyllanescconnect(signalMapper, static_cast(&QSignalMapper::mapped),
[=](int i){ /* ... */ });
- ikleschenkov