Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing QString into file is weird

Writing QString into file is weird

Scheduled Pinned Locked Moved General and Desktop
qstringaddresswrite
5 Posts 2 Posters 2.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jjan
    wrote on last edited by jjan
    #1

    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);
    				printf(window->qvaptDllPath.toStdString().c_str());
    				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

    1 Reply Last reply
    0
    • sneubertS Offline
      sneubertS Offline
      sneubert
      wrote on last edited by
      #2

      Hi jjan,

      add QIODevice::Text flag to f.opencall

      J 1 Reply Last reply
      1
      • sneubertS sneubert

        Hi jjan,

        add QIODevice::Text flag to f.opencall

        J Offline
        J Offline
        jjan
        wrote on last edited by jjan
        #3

        @sneubert

        Thanks for this, but this returns:

        QFile::open: File access not specified.

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

        1 Reply Last reply
        0
        • sneubertS Offline
          sneubertS Offline
          sneubert
          wrote on last edited by
          #4

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

          J 1 Reply Last reply
          1
          • sneubertS sneubert

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

            J Offline
            J Offline
            jjan
            wrote on last edited by
            #5

            @sneubert

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved