Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Text output.

Text output.

Scheduled Pinned Locked Moved Qt Creator and other tools
10 Posts 6 Posters 6.0k 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.
  • K Offline
    K Offline
    karhu44
    wrote on last edited by
    #1

    Hi,

    I am using Qt Creator 2.0.1 based on Qt 4.7.0 (32 bit); built on Aug 24 2010 at 11:00:55 from revision 97d831e3de.
    The following piece of source code:

    @ QFile data ("iotest.txt");
    if (data.open(QFile::WriteOnly | QFile::Truncate)) {
    QTextStream out(&data);
    out << "Test1:" << endl;
    out << "Test2\r" << endl;
    out << "Test3" << qSetFieldWidth(5) << 1234 << "\r\n";
    data.close();
    }
    @
    produces the output to the text file:

    Test1:Test2
    Test3 1234

    It seems to me that endl does not work properly. Can somebody from technical support comment this.

    Best regards,
    Grzegorz

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      Depends on what program you use to open the output file, with Notepad++ or Wordpad you will have:
      Test1:
      Test2
      Test3 1234

      But if you open with Notepad then you always need the windows version "\r\n" for a new line

      LE: also you can use the QIODevice::Text flag to cause the end-of-line conversion from "\n" to "\r\n" on Windows

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • K Offline
        K Offline
        karhu44
        wrote on last edited by
        #3

        Hi,

        In my opinion the compiler should recognise the operating system the executable is generated for and should behave respectively. That’s why I asked technical support for comment.

        Proposed solution is kind of amateur and widely known to experienced programmers.

        Best regards,
        Grzegorz

        1 Reply Last reply
        0
        • ZlatomirZ Offline
          ZlatomirZ Offline
          Zlatomir
          wrote on last edited by
          #4

          I apologize for my amateur solution

          If the Troll's solution (QIODevice::Text) for this isn't good enough and you want a real solution i suggest you contact Gcc and/or Visual Studio teams, since they are making the C++ compilers, or contact Microsoft and suggest to change the way their operating system is behaving in this problem.

          https://forum.qt.io/category/41/romanian

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #5

            [quote author="Grzegorz Szewczyk" date="1294609110"]Hi,

            In my opinion the compiler should recognise the operating system the executable is generated for and should behave respectively. That’s why I asked technical support for comment.

            Proposed solution is kind of amateur and widely known to experienced programmers.
            [/quote]

            It's not amateur at all. That's what endl does. http://doc.trolltech.com/4.7/qtextstream.html#endl

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fcrochik
              wrote on last edited by
              #6

              The idea is to allow you to fine tune how the file is created regardless of the platform so you can use the same code to open "the same file" regardless of the platform. For cross platform applications this is a MUST.

              Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                [quote author="Grzegorz Szewczyk" date="1294606854"]
                ...
                It seems to me that endl does not work properly. Can somebody from technical support comment this.
                [/quote]

                Hi Grzegorz,

                This is a community forum, not a Qt support forum. Some of the Trolls hang around here, but not for official support.

                And as peppe said, it does exactly what is described, it writes a \n to the file. If the editor of your choice needs \r\n, you have to set the QIODevice::Text flag, and it should work.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  [quote author="Zlatomir" date="1294609782"]I apologize for my amateur solution [/quote]
                  I love the smell of cynism in the morning! :-)

                  1 Reply Last reply
                  0
                  • ZlatomirZ Offline
                    ZlatomirZ Offline
                    Zlatomir
                    wrote on last edited by
                    #9

                    @Andre: that is not the case, i really am an amateur programmer and i wouldn't have bothered him with my advices if i knew he already knows the solution ;)

                    https://forum.qt.io/category/41/romanian

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fcrochik
                      wrote on last edited by
                      #10

                      [quote author="Zlatomir" date="1294654121"]@Andre: that is not the case, i really am an amateur programmer and i wouldn't have bothered him with my advices if i knew he already knows the solution ;)[/quote]

                      Amateur or not I think Grzegorz's answer should be nicer - let's hope it was not intentional. This is a community forum and anybody answering questions is trying to help by providing opinions and/or suggestions - no guarantees.

                      Also, when answering a question we don't have any way of knowing the author's level of expertise and, most of the time, have to start by assuming they can be missing something obvious - I don't see any problem with Zlatomir's answer.

                      Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

                      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