traducerad traducerad - 1 year ago 461
C++ Question

Qt C++: static assertion failed: Signal and slot arguments are not compatible

I am trying to start a countdown timer in a workerthread when the user clicks a pushbutton. The value at which the timer starts the count down depends on the selected radius button from my GUI.

I use a signalmapper to pass the starting value from the timer as a parameter. However I get this error when trying to compile my code:

static assertion failed: Signal and slot arguments are not compatible


My code:

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);
};


Could someone explain me what I may be doing incorrectly?

Thanks

Answer Source

connect(myThread, &QThread::started, signalMapper, SLOT(map()) );

connect(signalMapper, SIGNAL(mapped(int)), workerObj, SLOT(&workerTimer::countDown(int)));

You are mixing 2 kinds of connections rendering the entire statement meaningless. see http://doc.qt.io/qt-5/signalsandslots.html

connect(myThread, SIGNAL(started()), signalMapper, SLOT(map()) );

connect(signalMapper, SIGNAL(mapped(int)), workerObj, SLOT(countDown(int)));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download