Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child thread executes custom signal and crashes when updating interface content #53

Closed
zzh151223 opened this issue Apr 27, 2022 · 2 comments

Comments

@zzh151223
Copy link

zzh151223 commented Apr 27, 2022

Describe the bug
JVM crashes when child thread executes custom signal .emit() to update content

Expected behavior
Request the web page in the child thread and return the data, output the data to the form

Screenshots
image

Additional context

        new QThread(){
            @Override
            public void run(){
                //Request a web page and get the return value
                .......
                // customsignal.emit()
                customsignal.emit()
            }
        }.start();

================================================
        //customsignal execute
        tablewidget.setItem(0,0, QTableWidgetItem(The value returned by the page))  // program crashes here
@zzh151223
Copy link
Author

zzh151223 commented Apr 27, 2022

new QThread(){
    @Override
    public void run(){
    //Request a web page and get the return value
    .......
    tablewidget.setItem(0,0, QTableWidgetItem("test"))  // program crashes here
}
}.start();

This will also give an error

@omix
Copy link
Contributor

omix commented Apr 27, 2022

QTTablewidget.setItem() is thread affine, i.e. you cannot use it outside the main thread.
The method throws an QThreadAffinityException. The application crashes because QThread.run() must not throw any exceptions.

QThread.create(()->{
    tablewidget.setItem(0,0, QTableWidgetItem("test"));
});

Will not crash but print the thrown exception.

Avoid QThreadAffinityException by placing the setItem operation in main thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants