繁体   English   中英

Qthread信号发出未连接

[英]Qthread signal emit not connecting

我有两个正在连接的信号,一个没有。

我有一个mainwindow小部件来显示由Qthread处理的图像,该图像将原始图像和处理后的图像发射到显示它们的mywidow上,这是可行的。 我还想从此线程每秒发送一帧计算,但它不会连接。

所有代码在这里: https : //github.com/ianzur/qtGui_imageProcessing

mainwindow.cpp:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

// Timer for UI responsivness
tmrTimer = new QTimer(this);
connect(tmrTimer,SIGNAL(timeout()),this,SLOT(UpdateGUI()));
tmrTimer->start(20);

// Set initial sliders postion (for selecting ROI)
ui->SldLower->setSliderPosition(0);
ui->SldUpper->setSliderPosition(480);
ui->SldLeft->setSliderPosition(0);
ui->SldRight->setSliderPosition(640);

//connections to video processor thread

const bool c = connect(&processor,SIGNAL(outFPS(float)),ui->FPS,SLOT(setNum(float)));
connect(&processor,SIGNAL(inDisplay(QPixmap)),ui->inVideo,SLOT(setPixmap(QPixmap)));
connect(&processor,SIGNAL(outDisplay(QPixmap)),ui->outVideo,SLOT(setPixmap(QPixmap)));


qDebug() << "connected" << c;
}

线程声明

    class ProcessorThread : public QThread
    {
  Q_OBJECT


  public:
  explicit ProcessorThread(QObject *parent = 0);
  void update(QRect r, float low, float high);
  int CLOCK();
  float avgfps();

  signals:
  void inDisplay(QPixmap pixmap);
  void outDisplay(QPixmap pixmap);
  void outFPS(float fps);

  protected:
  void run() override;

  private:
  cv::VideoCapture capture;

  //Region of interest
  cv::Rect myROI;

  float lowHz;
  float highHz;
  //float fps;
  int _fpsstart=0;
  float _avgfps=0;
  float _fps1sec=0;

  };

线程定义

    ProcessorThread::ProcessorThread(QObject *parent) : QThread(parent)
 {

}

int ProcessorThread::CLOCK()
{
struct timespec t;
clock_gettime(CLOCK_MONOTONIC,  &t);
return (t.tv_sec * 1000)+(t.tv_nsec*1e-6);
}

float ProcessorThread::avgfps()
{
if(CLOCK()-_fpsstart>1000)
{
    _fpsstart=CLOCK();
    _avgfps=0.9*_avgfps+0.1*_fps1sec;
    _fps1sec=0;
}

_fps1sec++;
return _avgfps;
}

void ProcessorThread::run()
{
VideoCapture camera(0);

cv::Mat inFrame, outFrame, cropped, bit;

while(camera.isOpened() && !isInterruptionRequested())
{
    camera >> inFrame;

    if(inFrame.empty())
        continue;

    outFrame = inFrame.clone();

    cropped = inFrame(myROI);

    bitwise_not(cropped, bit);

    bit.copyTo(outFrame(myROI));

    //qDebug() << avgfps();

    emit outFPS(avgfps());

    emit inDisplay(QPixmap::fromImage(QImage(inFrame.data,inFrame.cols,inFrame.rows,inFrame.step,QImage::Format_RGB888).rgbSwapped()));

    emit outDisplay(QPixmap::fromImage(QImage(outFrame.data,outFrame.cols,outFrame.rows,outFrame.step,QImage::Format_RGB888).rgbSwapped()));


}
}

void ProcessorThread::update(QRect r, float low, float high)
{
this->myROI = cv::Rect(r.x(),r.y(),r.width(),r.height());

this->lowHz = low;
this->highHz = high;
}

我不知道为什么只有outFPS无法连接。

我的第一个想法是,看这行:

const bool c = connect(&processor,SIGNAL(outFPS(float)),ui->FPS, SLOT(setNum(float)));

在您的UI中,FPS看起来像QPlainTextEdit。 我没有看到该类的setNum()插槽记录。 QLabel有一个(它需要一个int或double值),这就是您要使用的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM