Hi guys
I've created a small window (derived from QWidget) with a QProgressBar inside. Then I've created a thread class (derived from QThread). When i launch my file I create the window and the start the thread with an overloaded run method. I want that the thread (during the run) updates the progress bar at each operation. I've thought to the slots and signals system but I have problems: I've implemented a slot in the window class that updates the value of the progress bar and a signal in the thread class that invokes the slot method. In detail:
data and methods
public slots:
void updatePB(int);
};
void Window::updatePB(int val) { pb->setValue(val); }
class Window: public QWidget {
data and methods
QProgressBar* pb;
public slots:
void updatePB(int);
};
void Window::updatePB(int val) { pb->setValue(val); }
To copy to clipboard, switch view to plain text mode
data and methods
Window* pointerWindow;
signals:
void signalUpdate(int);
};
Thread::Thread (Window* w) {
pointerWindow = w;
connect (this,SIGNAL(signalUpdate(int)), pointerWindow, SLOT(updatePb(int)));
}
void Thread::run() {
while (true) emit signalUpdate(30);
}
class Thread: public QThread {
data and methods
Window* pointerWindow;
signals:
void signalUpdate(int);
};
Thread::Thread (Window* w) {
pointerWindow = w;
connect (this,SIGNAL(signalUpdate(int)), pointerWindow, SLOT(updatePb(int)));
}
void Thread::run() {
while (true) emit signalUpdate(30);
}
To copy to clipboard, switch view to plain text mode
Now the questions are:
a) why doesn't it compile? It returns the error: no maching function for call to Thread::connect(Thread* const,const char*, Setup*&,const char*). I think the problem is the pointer to the window but I don't know why (I create the thread with: "Thread* th=new Thread(this);"
b) should I define the signal method?
Thanks a lot =)
Bookmarks