Segmentation fault while accessing textBox from callback
-
I have simple callback functions that provides data to be shown on QT widget main form. As soon breakpoint reaches setText() I have exception
Segmentation fault
:void MainWindow::SetAmount(int value) { ui->tbAmount->setText( QString::number(value) ); }
Why I'm geting souch error? When I call
SetAmount()
from button click it runs fine. -
Hi
Do you call it from another thread? -
I have simple callback functions that provides data to be shown on QT widget main form. As soon breakpoint reaches setText() I have exception
Segmentation fault
:void MainWindow::SetAmount(int value) { ui->tbAmount->setText( QString::number(value) ); }
Why I'm geting souch error? When I call
SetAmount()
from button click it runs fine.@column said in Segmentation fault while accessing textBox from callback:
As soon breakpoint reaches setText()
Do you mean when it hits breakpoint on that line before it executes the line, or do you mean as it executes that line?
But answer @mrjj first.
-
@column said in Segmentation fault while accessing textBox from callback:
ui->tbAmount
I would guess the either ui or ui->tbAmount is not initialized.
-
Hi,
Yes that is a problem, GUI elements should only be accessed/modified in the GUI thread. The cleanest way would be to use QMetaObject::invokeMethod using
QueuedConnection
so you ensure that thesetText
will be called in the correct context. -
@column said in Segmentation fault while accessing textBox from callback:
As soon breakpoint reaches setText()
Do you mean when it hits breakpoint on that line before it executes the line, or do you mean as it executes that line?
But answer @mrjj first.