这里我添加了部分代码,我有我的主函数和MainWindow类
基本上,我的init((函数应该被触发,以填充timercalldisplay((函数中的display_images队列,所以我从我的主调用它
但我无法进入timercalldisplay((,通过SLOT调用它,而init((正在执行
有人能说出我犯了什么错误吗
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void init();
QTimer *timer;
public slots:
void timercalldisplay();
private:
Ui::MainWindow *ui;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.init();
return a.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timercalldisplay()));
timer->start(500);
}
void MainWindow::timercalldisplay()
{
qDebug() << display_images.size(); //not reaching here
while(display_images.size())
{
Mat img = display_images.front();
QPixmap pixmap;
QImage qimg(img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
pixmap = QPixmap::fromImage(qimg.rgbSwapped());
ui->label->setPixmap(pixmap);
ui->label->setScaledContents(true);
ui->label->show();
QThread::currentThread()->msleep(1000);
qApp->processEvents();
display_images.pop();
}
}
connect(timer, SIGNAL(timeout()), this, SLOT(timercalldisplay()));
将((从连接中取出固定
connect(timer, &QTimer::timeout, this, &MainWindow::timercalldisplay);
也在你的构造函数更改
QTimer *timer = new QTimer(this);
至
timer = new QTimer(this);
根据新发布的进行更新