当前位置:网站首页>QObject::connect: Cannot queue arguments of type ‘QTextCursor‘ (Make sure ‘QTextCursor‘ is registere

QObject::connect: Cannot queue arguments of type ‘QTextCursor‘ (Make sure ‘QTextCursor‘ is registere

2022-06-13 08:59:00 one-rabbit

About how to solve this problem ; In fact, you are in the slot function when the thread comes back Called ui Code for .

Solution ; The slot function returned from the thread is the same Slot function instead of , instead of use lambda expression

 1//cpp Threads 
  caiJi=std::thread([=](){
    
        qDebug()<<" Current thread id"<<QThread::currentThreadId();
        emit testxx(0);
   });
// Signal and slot processing part 
	 connect(this,&MainWindow::testxx,[&](int i){
    
        qDebug()<<" end id"<<QThread::currentThreadId();
        ui->textEdit->append(QString::number(i));
     }
//2、Qt Threads 
	myT=new Mythread;
    thread=new QThread;

    myT->moveToThread(thread);
    thread->start();
 // Where the signal is sent  
void Mythread::Test1()
{
    
    qDebug()<<" Funny :"<<QThread::currentThreadId();
    emit test2(" Youth is extraordinary ");
}  

  // Signal and slot processing part  
     connect(myT,&Mythread::test2,[=](QString str){
    
        ui->textEdit->append(str);
    });

By using signal and slot, we can The execution of the slot function is replaced by Current thread

 connect(myT,&Mythread::test2,this,&MainWindow::test2);
 void MainWindow::test2(QString str)
 {
    
    qDebug()<<" Signal and slot thread id"<<QThread::currentThreadId();
    ui->textEdit->append(str);
 }

 Insert picture description here

原网站

版权声明
本文为[one-rabbit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270535463372.html