Writing QString into file is weird

  • I try to write an QString into an file with this code:

    // Write new.
    			QFile f(QDir::homePath() + "/test/conf");
    			if (f.open(QIODevice::ReadWrite))
    				QTextStream wr(&f);
    				wr << "# do not edit\n" << endl
    				<< "[qvapt]\nqvapt_path = " << window->qvaptDllPath << endl
    				<< "qvapt_name = " << window->qvaptDllVersion << endl << endl
    				<< "[window]\nlast_window_state = " << window->theWindowState
    				<< endl;
    						// TODO: more

    qvaptDllPath is QString qvaptDllPath = "/home/jan/qvapt-0.1.1/qvapt_sdk.dll"; (currently pre-defined for testing), but all what I get is this in the file:

    qvapt_path = 0xcccc060

    How can I fix this to write the "real" string?

    ~ jan

  • Hi jjan,

    add QIODevice::Text flag to f.opencall

  • @sneubert

    Thanks for this, but this returns:

    QFile::open: File access not specified.

    BTW: Writing window->theWindowState which is QString theWindowState; works perfectly!

  • with add i mean
    f.open(QIODevice::ReadWrite | QIODevice::Text)

  • @sneubert

    Works perfectly! I've made the mistake to add it over an comma. Thanks!

Log in to reply

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