GTK3 : Does gtk_print_operation_run needs to be executed in main thread?

Hi,

I’m working on GTK3 application in C. As print is an time consuming operation, I’m doing the print operation on NON-Main Thread.

I’m using gtk_print_operation_run to start the print. But in Non-Main thread if I pass GtkPrintOperationAction as GTK_PRINT_OPERATION_ACTION_PRINT, print works fine, but if I pass GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG the print will crash with error sayiny `

(TWTallySCPNative:1032596): Gdk-ERROR **: 17:14:11.920: The program ‘TWTallySCPNative’ received an X Window System error.
This probably reflects a bug in the program.
The error was ‘BadValue (integer parameter out of range for operation)’.
(Details: serial 1771 error_code 2 request_code 18 (core protocol) minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the GDK_SYNCHRONIZE environment
variable to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)

and sometime it will crash without any error.

Considering I will always run my print with GTK_PRINT_OPERATION_ACTION_PRINT, is it okay to use gtk_print_operation_run API in NON- Main thread?

Thank You

Every GTK function must be executed in the same thread that initialised GTK and it’s running the main loop. You cannot call any GTK API from other threads.

1 Like

Thank You, this was helpful

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.