QIODevice::write: device not open” when file is open



  • hi if i am using some file and it's openned. I can't write there? This error can crash my program? or it's only one alert?


  • Lifetime Qt Champion

    Hi,

    How did you open the file ? Are you sure that you are not writing to a ReadOnly file ?



  • @Jeronimo

    This error can crash my program? or it's only one alert?

    If you are not writing any thing, it can not be crash. It is better to post the your exact error . So that , its easy to say the specific solution.

    Better to post some of your code to find the error. Here is the sample code that you can read and write to the file. It can be done in many ways, this is some sample rough code.

    Void MainWindow :: someFucntionName() {
         QString path = qApp->applicationDirPath(); //location of the file, assuming in application dir
    	path.append("./yourTextFile.txt");
    	QFile fileUrl(path);
    	if( fileUrl.open(QIODevice::ReadWrite | QIODevice::Text) ) {      
            QTextStream out(&fileUrl);
            out<< "something" << endl;
        }
    

Log in to reply
 

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