Runtime error when cancelling QFileDialog



  • Good pm! I'm new to Qt Creator and can't seem to find a thread in any forum that is helpful for my issue. Whenever I cancel the QFileDialog::getOpenFileNames function, i get a runtime error "Invalid parameter passed to C runtime function." This happens when using both (X) button and cancel button. Error happens when the program runs the function and does not reach checking if QStringList is null/empty...Help would be greatly appreciated



  • Hi,
    please show the code that you are speaking of.
    -Michael.



  • QStringList fileNames;
    fileNames = QFileDialog::getOpenFileNames(this, "Select a file to open...","/home","Excel (*.xls)");



  • Hi,
    you are still a bit sparse on details.
    Does it happen in debug or release mode?
    Does it happen even when you run the program outside of QtCreator?
    Which OS?
    Which Qt version?
    Which QtCreator version?
    -Michael.



  • It happens while running the code in Qt Creator. I have not tried creating an executable program so I can't say if it will happen outside Qt Creator.. but isn't that how it goes, if it happens in debug mode it will happen during exe run as well? OS is Windows 7. Qt Creator Version is 5.7.0. This is the error message
    0_1482398217006_upload-918dd5b9-ee7e-40e9-9bf9-1aa4caba4c5c



  • Your problem is almost surely not in the code you posted, could you show us what you do next with fileNames?



  • there's a checking of whether or not the list is empty and the program should inform the user if it was cancelled. but it doesn't even reach the checking. i tried creating a messagebox before the checking just to see if fileNames was populated. it did not reach that part of the code either. From observation, the program crashes when QFileDialog::getOpenFileNames is being cancelled. I just don't know how I'm supposed to handle it. I can't even determine what the return value is because the system crashes first.

    if(fileNames.empty())// CHECKS IF NOT EMPTY OR CANCELLED
    {
    QMessageBox cancelled;
    cancelled.setWindowTitle("Failed File Selection");
    cancelled.setText("No file Selected");
    cancelled.exec();
    }
    else



  • @mjgfm said in Runtime error when cancelling QFileDialog:

    I have not tried creating an executable program

    I do not understand how QtCreator can execute this code without you having an executable program.
    -Michael.


  • Qt Champions 2016

    Hi
    You should try with a clean default project.
    And only call QFileDialog::getOpenFileNames(xxx)

    If it can crash on that line alone then your windows is not in fully working condition :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.