【问题标题】:How Use QTimer Command如何使用 QTimer 命令
【发布时间】:2021-12-25 08:19:12
【问题描述】:

我在使用 QTimer 命令时遇到问题。 我没有任何语法错误,但我在 qglobal.h 和 qobjectdefs_impl.h 中有 2 个错误,我不理解它们。

MainWindow.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
void MainWindow::updatewindow()
{
    Mat frame;
    capture >> frame;
    cvtColor(frame, frame, cv::COLOR_BGR2RGB);
    QImage image((uchar*)frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
    QPixmap temp_img = QPixmap::fromImage(image);
    ui->label2->setPixmap(temp_img);
}

void MainWindow::on_pushload_clicked()
{
    QTimer *timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, SLOT(updatewindow()));
    timer->start(20);
}

我在使用 QTimer 命令时遇到问题。 我没有任何语法错误,但我在 qglobal.h 和 qobjectdefs_impl.h 中有 2 个错误,我不明白。

和 mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>  
#include <QPixmap>
#include <QTimer>
#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);

    ~MainWindow();

private:
    QPixmap Iblackwhite,IMG_Color{};
    QImage image {};
    cv::VideoCapture capture{};
private slots:
      void  updatewindow();

      void on_pushload_clicked();
private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

请帮我解决我的问题。

【问题讨论】:

  • 您将 Qt4 风格与 Qt5 风格信号混合在一起。在 Qt4 信号中,使用 Qt 实现的反射在运行时解析。在 Qt5 中,信号可以连接类型安全并在编译时解析(以防编译器错误)。您不能在一个应用程序中使用 Qt4 和 Qt5 的样式,但不能在一个应用程序中使用 connect() - 这根本不受支持。 (不是你误会我的意思:Qt 5 风格的信号显然更可取。);-)

标签: loops qt opencv video-capture qtimer


【解决方案1】:

使用&amp;MainWindow::updateWindow 而不是SLOT(updatewindow())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    • 2017-12-11
    • 2020-06-23
    • 1970-01-01
    相关资源
    最近更新 更多