小编hag*_*gor的帖子

是std :: thread的共享指针是一种不好的做法?

使用std :: shared_ptr <std :: thread>是否有意义?逻辑很简单:如果不需要线程,删除它,如果需要new,则重新定位它.有没有办法将这个概念与汇集线程进行比较?

我确实知道我系统中线程的确切数量(我开发了图像处理算法,我想给每个"算法"类的子项一个单独的线程(也许是为了私有,然后不需要shared_ptr),这个算法将运行,如果没有提供图像,则将此私有线程空闲.这是一个坏概念吗?

c++ multithreading c++11

5
推荐指数
1
解决办法
430
查看次数

C++ Qt GUI更新

我是Qt的新手,因此我遇到了GUI更新问题.我有2个类:ControlWidget在主线程和CameraController单独的线程中.

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    CameraController *cameraController = new CameraController;;
    ControlWidget *main_window = new ControlWidget;
    Thread getImageThread; 
    cameraController->moveToThread(&getImageThread);
    getImageThread.start();
    QTimer get_images_timer;
    QObject::connect(&get_images_timer, SIGNAL(timeout()), cameraController, SLOT(onTimerOut()), Qt::QueuedConnection);
    QObject::connect(cameraController, SIGNAL(sendLabel(QImage)), main_window, SLOT(getImage(QImage)), Qt::QueuedConnection);
    QObject::connect(&get_images_timer, SIGNAL(timeout()), main_window, SLOT(update()), Qt::QueuedConnection);
    get_images_timer.start(2000);
    app.exec();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

因此,每2秒我想从相机线程获取图像并将它们发送到主线程(动作发生,所以我QImage在main_window对象).然后我想把这个QImage放到cam1和cam2上QLabel.在这里我被困住了:

第一:当我使用setPixmap()方法QLabel.width()QLabel.height()不同,那么image.width()image.height()pixmap.width()pixmap.height().

第二:我无法想象QLabel.如果我什么this->ImageLayout->addWidget(cam1)都不做的话.this->update也没有帮助.

我有一个额外的GUI更新工作者吗?我究竟做错了什么?

源代码以获取更多信息:

CameraController.h …

c++ qt

1
推荐指数
1
解决办法
149
查看次数

标签 统计

c++ ×2

c++11 ×1

multithreading ×1

qt ×1