My code contains a function which takes a lot of time to compute. To make it feel more responsive, I wanted to visualize every tenth of the progress with a progress bar. However, the function is implemented in another class other than my Main Widget class and I cannot access the ui elements of the Widget class. I tried putting a signal which can be emitted during the function, however it comes up as an error. The relevant code looks like this:
//Class cpp implementation
void Dataset::calculateNew(){
for(int i = 0; i<1000; i++){
if(i%100==0)
emit valueChanged(i); //first Error
for(int j = 0; j<1000; j++){
for(int k=0; k<1000; k++){
//Expensive Matrix calculation
}
}
}
}
//Class .h implementation
signal:
valueChanged(int value);
//Widget implementation
connect(Dataset::calculateNew(), SIGNAL(valueChanged(int)), this, SLOT(updateProgressBar(int))); //second Error here
Am I thinking in the right way? What should I do to make it work? Or is there another way to access and change ui Elements of the Widget class.
Note: I tried including the "widget.h" in Dataset class, but it isn´t recognized as a class to be included,
Hard to say without the minimal example, but I guess the problem lies in your call to connect:
connect(Dataset::calculateNew(), SIGNAL(valueChanged(int)), this, SLOT(updateProgressBar(int))); //second Error here
Provided your dataset object is called ds
, it should look like this:
connect(&ds, SIGNAL(valueChanged(int)), this, SLOT(updateProgressBar(int)));
BTW, why don't you use the new signal-slot syntax based on fucntion pointers? Are you still on QT4?