Hi all,
I'm really new of QT programming and I need to acess my ui pointer from a thread to refresh an image that's displayed in my window.
How can i do this? Many thanks to everyone who will help me 
Gian
I post some code to explain it better:
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}
{
Q_OBJECT
public:
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
MainWindow.cpp:
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
MyThread* myT = new MyThread();
myT->run();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
MyThread* myT = new MyThread();
myT->run();
}
To copy to clipboard, switch view to plain text mode
getFrameThread.cpp:
void MyThread::run()
{
forever {
//MainWindow *ui = MainWindow::ui;
CvCapture* camera;
camera = cvCreateCameraCapture(0);
assert(camera);
IplImage * cvimage=cvQueryFrame(camera);
assert(cvimage);
// IMG ELABORATION SKIPPED
MainWindow::ui->imgLabel->setPixmap(CVUtils::getImage(cvimage)); // This is the row i want to fix
}
}
void MyThread::run()
{
forever {
//MainWindow *ui = MainWindow::ui;
CvCapture* camera;
camera = cvCreateCameraCapture(0);
assert(camera);
IplImage * cvimage=cvQueryFrame(camera);
assert(cvimage);
// IMG ELABORATION SKIPPED
MainWindow::ui->imgLabel->setPixmap(CVUtils::getImage(cvimage)); // This is the row i want to fix
}
}
To copy to clipboard, switch view to plain text mode
getFrameThread.h:
#include "CVUtils.h"
#include <QThread>
{
Q_OBJECT
public:
MyThread();
public:
void run();
MainWindow* ui;
};
#include "CVUtils.h"
#include <QThread>
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread();
public:
void run();
MainWindow* ui;
};
To copy to clipboard, switch view to plain text mode
Bookmarks