//mainwindow.h关键代码
signals:
void sig_show(QListWidget* pListWidget);
public slots:
void slot_startButtonClicked();
private:
Show* m_pShow;
QThread* m_pShowThread;
//mainwindows.cpp关键代码
//MainWindow的构造函数中的代码
m_pShowThread = new QThread();
m_pShow = new Show();
m_pShow->moveToThread(m_pShowThread);
connect(ui->startButton, SIGNAL(clicked()), this, SLOT(slot_startButtonClicked()));
connect(this, &MainWindow::sig_show, m_pShow, &Show::slot_showHandle, Qt::QueuedConnection);
m_pShowThread->start();
//slot_startButtonClicked中的代码
QListWidget* pListWidget = ui->listWidget;
emit sig_show(pListWigdet);
//show.h中的代码
public slots:
void slot_showHandle(QListWidget* pListWidget);
//show.cpp中的代码
void Show::slot_showHandle(QListWidget* pListWidget)
{
pListWidget->addItem("abc");
}