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. Why won't my program write to a file?
Forum Updated to NodeBB v4.3 + New Features

Why won't my program write to a file?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.5k Views
  • 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.
  • H Offline
    H Offline
    Hubbard
    wrote on last edited by
    #1

    0_1525494089136_0d9b76b4-72ea-4d07-89df-7749a35118a9-image.png

    0_1525494134485_a5cb4349-4f98-4f76-824d-13832064064c-image.png

    0_1525494162706_9c4cd305-b0da-4b49-9685-26171d731c56-image.png

    At the end of a normal program run in debugMode nothing happens, the file remains empty. The same thing happened before. Is it a directory issue?

    DiracsbracketD 1 Reply Last reply
    0
    • H Hubbard

      0_1525494089136_0d9b76b4-72ea-4d07-89df-7749a35118a9-image.png

      0_1525494134485_a5cb4349-4f98-4f76-824d-13832064064c-image.png

      0_1525494162706_9c4cd305-b0da-4b49-9685-26171d731c56-image.png

      At the end of a normal program run in debugMode nothing happens, the file remains empty. The same thing happened before. Is it a directory issue?

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @Hubbard

      if (debugMode)
      {
      }
      

      Are you sure that block is being executed, i.e. debugMode equals true/1 ?

      H 1 Reply Last reply
      0
      • DiracsbracketD Diracsbracket

        @Hubbard

        if (debugMode)
        {
        }
        

        Are you sure that block is being executed, i.e. debugMode equals true/1 ?

        H Offline
        H Offline
        Hubbard
        wrote on last edited by
        #3

        @Diracsbracket yes

        DiracsbracketD 1 Reply Last reply
        0
        • H Hubbard

          @Diracsbracket yes

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @Hubbard
          Sorry for the obvious questions. I hope you are not taking offence...
          Are your sure you are looking at the correct output dir when you are looking for the file?
          Is the file being created even when you write nothing to it? (i.e. just open/close it?)

          P.S.
          When writing strings to a QDataStream I usually get additional strange characters if I just
          use the << stream operator. Instead, I have to use:

          outputStream->writeRawData("test", 4);
          

          For example, if I use

          *outputStream << QString("test");
          

          or

          *outputStream << "test";
          

          I get the following file:

          0_1525497934610_6049225e-ef69-4c8a-94d9-2fe209e6f9b7-image.png

          While using writeRawData() gives:

          0_1525497986026_d976d712-d74e-46f4-982c-ddf3fca80225-image.png

          1 Reply Last reply
          1
          • H Offline
            H Offline
            Hubbard
            wrote on last edited by
            #5

            The file is not so I guess I am looking at the wrong directory, where does Qt like to create files to??

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hubbard
              wrote on last edited by
              #6

              Aah I see, it creates the log to the build file, that makes sense, thank you!

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hubbard
                wrote on last edited by
                #7

                The streams do seem to be causing issues, they won't show the ints, just a box

                DiracsbracketD 1 Reply Last reply
                0
                • H Hubbard

                  The streams do seem to be causing issues, they won't show the ints, just a box

                  DiracsbracketD Offline
                  DiracsbracketD Offline
                  Diracsbracket
                  wrote on last edited by Diracsbracket
                  #8

                  @Hubbard said in Why won't my program write to a file?:

                  The streams do seem to be causing issues, they won't show the ints, just a box

                  Don't forget you are writing binary data (since that is what QDataStream is for)! So when you open it in a text editor, those numbers will usually not correspond to valid displayable characters (e.g. ascii). If you write an 8, it will write the binary 8, not the ascii character 8.

                  If you want those numbers as ascii, then you need to use the QString::number() conversion.
                  For plain text, you could otherwise also have used QTextStream instead.

                  1 Reply Last reply
                  5

                  • Login

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