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
Forum Updated to NodeBB v4.3 + New Features

Writing QString into file is weird

Scheduled Pinned Locked Moved General and Desktop
qstringaddresswrite
5 Posts 2 Posters 2.0k 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 21 May 2015, 14:22 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
    • S Offline
      S Offline
      sneubert
      wrote on 21 May 2015, 14:27 last edited by
      #2

      Hi jjan,

      add QIODevice::Text flag to f.opencall

      J 1 Reply Last reply 21 May 2015, 14:30
      1
      • S sneubert
        21 May 2015, 14:27

        Hi jjan,

        add QIODevice::Text flag to f.opencall

        J Offline
        J Offline
        jjan
        wrote on 21 May 2015, 14:30 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
        • S Offline
          S Offline
          sneubert
          wrote on 21 May 2015, 14:31 last edited by
          #4

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

          J 1 Reply Last reply 21 May 2015, 14:35
          1
          • S sneubert
            21 May 2015, 14:31

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

            J Offline
            J Offline
            jjan
            wrote on 21 May 2015, 14:35 last edited by
            #5

            @sneubert

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

            1 Reply Last reply
            0

            4/5

            21 May 2015, 14:31

            • Login

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