I have a function that gets called in a separate thread from the main one when a button gets clicked and it calls the QFileDialog::getSaveFileName()
function to get a file handle to the file the user saved, but I can't do that on a separate thread because it modifies the GUI and you're not allowed to do that.
How can I get around this?
QFileDialog::getSaveFileName()
returns file name, it does not try to open the file nor return the file handle.It's not clear from your question, but I assume that your button starts the thread to execute some lengthy task and to store the results to the file. So call
QFileDialog::getSaveFileName()
right there in the button click slot, obtain the file name and provide that name to the thread. Your thread will just read that file name, so probably there is no need for synchronization. And then, you just open the file with provided file name in that non-GUI thread.