Semaphore and multithread
-
I wrote the code without ui and it works. Then I wrote ui->label->setText("il valore della distanza in mm è: " + QString::number(distance)); into my code and code works with time of 1 second (its resultes are correct) and code doesnt work with time of 500 ms (its results are bad)
I dont understant why.
Senior suggest me that the resource is occuped by the other process
@jsulm I think you are right.
If with ui.label or without ui.label, I Always have ui in my code. But I'm not the boss and I have task :D -
@Montanaro
ok, just to make sure, so that I'm not going crazy:unsigned char MainWindow::poll() { unsigned short distance; qDebug() << " Polling started"; check_for_interrupt(ADDR, &distance); qDebug() << "valore distanza:" << distance; //ui->label->setText("il valore della distanza in mm è: " + QString::number(distance)); }
Results in the correct read of
120 distance
150 distance
180 distancebut
unsigned char MainWindow::poll() { unsigned short distance; qDebug() << " Polling started"; check_for_interrupt(ADDR, &distance); qDebug() << "valore distanza:" << distance; ui->label->setText("il valore della distanza in mm è: " + QString::number(distance)); }
results in
3000 distance
3000 distance
3000 distance?
-
@Montanaro
First, please answer @J-Hilk's latest question.There must be more going on in your code somewhere than you show... And for my part at least, I don't understand what the "resource" you refer to is....
I suggest you briefly test one more case. Try having:
qDebug() << "valore distanza:" << QString::number(distance); // <- this is changed, it uses `QString::number` // next line is still commented out //ui->label->setText("il valore della distanza in mm è: " + QString::number(distance));
Does this produce right or wrong output? If by any chance this also produces wrong output, it suggests that any call to a Qt method is causing a problem, not the
label->setText()
itself.