提问人:bjorn 提问时间:10/21/2020 更新时间:10/21/2020 访问量:196
C++ 和 QT 线程外部变量不起作用
C++ and QT thread extern variable not working
问:
我正在编写一个 C++ 程序,并且我正在将 QT 用于 GUI。我需要将数据从一个 QT 线程传递到另一个线程,所以我决定使用外部变量,但它不起作用。这是我的代码:
stream_buffer.h
#ifndef STREAM_BUFFER_H
#define STREAM_BUFFER_H
#include "opencv2/core.hpp"
extern cv::Mat frame_buffer;
#endif // STREAM_BUFFER_H
线程1.cpp
#include "stream_buffer.h"
//Some code
cv::Mat frame_buffer;
video_stream >> frame_buffer;
//other code
线程2.cpp
#include "stream_buffer.h
imshow("debug", frame_buffer);
在编译过程中,我收到错误。如果我也在 Thread2.cpp 中定义变量,它会编译,但它当然不起作用(因为它是一个局部变量,所以它不会从公共头文件中读取值)。unresolved external symbol frame_buffer in function void run in Thread2.cpp
frame_buffer
我该如何解决这个问题? 谢谢
答: 暂无答案
评论
extern cv::Mat frame_buffer;
只是一个声明。这个全局变量在哪里定义?Thread1.ccp
cv::Mat frame_buffer;
extern