Hello, I have the following problem:
I have to execute a long algorithm when a user pushes a button. So I created a new class that is a subclass from QThread and use the button push to start said thread. But I also want to have some sort of measure of the progress and for that I wanted to create a signal and a slot. So I made a little test program. However when I used connect, to connect my slot and signal I get a console message (I'm compiling in debug mode):
Object::connect: No such signal QThread:: p(int)
Object::connect: (receiver name: 'ConnectTryClass')
Where p is the name of my signal in my QThread subclass.
Here is the code for the Sender class (.cpp) (QThread decendant):
#include "Sender.h"
Sender::Sender()
{
}
void Sender::run(){
int N = 10000000;
int a;
for (int i = 0; i < N; i++){
a++;
double val = (double)(i+1)*100/double(N);
emit p((int)(val));
}
}
void Sender::p(int val){
}
Sender::~Sender()
{
}
#include "Sender.h"
Sender::Sender()
{
}
void Sender::run(){
int N = 10000000;
int a;
for (int i = 0; i < N; i++){
a++;
double val = (double)(i+1)*100/double(N);
emit p((int)(val));
}
}
void Sender::p(int val){
}
Sender::~Sender()
{
}
To copy to clipboard, switch view to plain text mode
and its header:
{
public:
Sender();
void run();
~Sender();
signals:
void p(int val);
};
class Sender: public QThread
{
public:
Sender();
void run();
~Sender();
signals:
void p(int val);
};
To copy to clipboard, switch view to plain text mode
And where I call the connec (ConnectTry.cpp)t:
#include "connecttry.h"
{
ui.setupUi(this);
sender = new Sender();
bool res = connect(sender,SIGNAL(p(int)),this,SLOT(on_p(int)));
if (res)
ui.teLog->append("Yes");
else{
ui.teLog->append("No");
}
}
void ConnectTry::on_p(int val){
ui.pbDone->setValue(val);
}
void ConnectTry::on_pbTest_clicked(){
sender
->start
(QThread::InheritPriority);
ui.teLog->append("Done");
}
#include "connecttry.h"
ConnectTry::ConnectTry(QWidget *parent): QMainWindow(parent)
{
ui.setupUi(this);
sender = new Sender();
bool res = connect(sender,SIGNAL(p(int)),this,SLOT(on_p(int)));
if (res)
ui.teLog->append("Yes");
else{
ui.teLog->append("No");
}
}
void ConnectTry::on_p(int val){
ui.pbDone->setValue(val);
}
void ConnectTry::on_pbTest_clicked(){
sender->start(QThread::InheritPriority);
ui.teLog->append("Done");
}
To copy to clipboard, switch view to plain text mode
Can any one tell me what I'm doing wrong?
Thank you
Bookmarks