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. how can I move the pointer in QFileStream to the end of the file?
Forum Updated to NodeBB v4.3 + New Features

how can I move the pointer in QFileStream to the end of the file?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 715 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.
  • R Offline
    R Offline
    RuWex
    wrote on last edited by
    #1

    for example I have this file:
    **
    Hello
    **
    and anotheer file that I want to copy the file to the end of the first file:
    **
    world
    **
    so I want it to be:
    **
    Hello
    world
    **
    and I open the files
    and I did:

    QFile file("Log_File.txt");
    QTextStream stream( &file );
    

    and now I want to move the pointer to the end of the file in order to copy the second file to his end.
    how to do it?

    J.HilkJ JonBJ 2 Replies Last reply
    0
    • R RuWex

      @J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:

      file.open(QIODeviceBase::Append | QIODeviceBase::Text);

      my program doesnt konw QIODeviceBase- do I have to add include?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #6

      @RuWex QIODevice:: Append and QIODevice::Text should also work, and those are included with QFile include


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • R RuWex

        for example I have this file:
        **
        Hello
        **
        and anotheer file that I want to copy the file to the end of the first file:
        **
        world
        **
        so I want it to be:
        **
        Hello
        world
        **
        and I open the files
        and I did:

        QFile file("Log_File.txt");
        QTextStream stream( &file );
        

        and now I want to move the pointer to the end of the file in order to copy the second file to his end.
        how to do it?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @RuWex

        QFile file("Log_File.txt");
        file.open(QIODeviceBase::Append | QIODeviceBase::Text);
        QTextStream stream( &file );
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        R 1 Reply Last reply
        3
        • R RuWex

          for example I have this file:
          **
          Hello
          **
          and anotheer file that I want to copy the file to the end of the first file:
          **
          world
          **
          so I want it to be:
          **
          Hello
          world
          **
          and I open the files
          and I did:

          QFile file("Log_File.txt");
          QTextStream stream( &file );
          

          and now I want to move the pointer to the end of the file in order to copy the second file to his end.
          how to do it?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #3

          @RuWex said in how can I move the pointer in QFileStream to the end of the file?:

          and anotheer file that I want to copy the file to the end of the first file:

          and now I want to move the pointer to the end of the file in order to copy the second file to his end.

          Then you should be opening the first file in append mode, and no "file seeking" by you is required.

          1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @RuWex

            QFile file("Log_File.txt");
            file.open(QIODeviceBase::Append | QIODeviceBase::Text);
            QTextStream stream( &file );
            
            R Offline
            R Offline
            RuWex
            wrote on last edited by
            #4

            @J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:

            file.open(QIODeviceBase::Append | QIODeviceBase::Text);

            my program doesnt konw QIODeviceBase- do I have to add include?

            JonBJ J.HilkJ 2 Replies Last reply
            0
            • R RuWex

              @J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:

              file.open(QIODeviceBase::Append | QIODeviceBase::Text);

              my program doesnt konw QIODeviceBase- do I have to add include?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #5

              @RuWex
              Why not search the documentation for QIODeviceBase to find the answer? https://doc.qt.io/qt-6/qiodevicebase.html, #include <QIODevice>, if #include <QFile> does not already do so.

              R 1 Reply Last reply
              1
              • R RuWex

                @J-Hilk said in how can I move the pointer in QFileStream to the end of the file?:

                file.open(QIODeviceBase::Append | QIODeviceBase::Text);

                my program doesnt konw QIODeviceBase- do I have to add include?

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #6

                @RuWex QIODevice:: Append and QIODevice::Text should also work, and those are included with QFile include


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                3
                • JonBJ JonB

                  @RuWex
                  Why not search the documentation for QIODeviceBase to find the answer? https://doc.qt.io/qt-6/qiodevicebase.html, #include <QIODevice>, if #include <QFile> does not already do so.

                  R Offline
                  R Offline
                  RuWex
                  wrote on last edited by RuWex
                  #7

                  @JonB said in how can I move the pointer in QFileStream to the end of the file?:

                  Why not search the documentation for QIODeviceBase to find the answer? https://doc-snapshots.qt.io/qt6-dev/qiodevicebase.html, #include <QIODevice>, if #include <QFile> does not already do so.

                  I tried to add #include <QIODevice> but it doesnt work:(![0_1672825578671_QIODevice.PNG](Uploading 100%)

                  JonBJ 1 Reply Last reply
                  0
                  • R RuWex

                    @JonB said in how can I move the pointer in QFileStream to the end of the file?:

                    Why not search the documentation for QIODeviceBase to find the answer? https://doc-snapshots.qt.io/qt6-dev/qiodevicebase.html, #include <QIODevice>, if #include <QFile> does not already do so.

                    I tried to add #include <QIODevice> but it doesnt work:(![0_1672825578671_QIODevice.PNG](Uploading 100%)

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @RuWex
                    So tell us what version of Qt you are using, we cannot guess? If it's Qt5 rather than Qt6 it would be QIODevice::... rather than QIODeviceBase::....
                    Alternatively did you try @J-Hilk's QIODevice::Append/Text without any extra #include?

                    R 1 Reply Last reply
                    3
                    • JonBJ JonB

                      @RuWex
                      So tell us what version of Qt you are using, we cannot guess? If it's Qt5 rather than Qt6 it would be QIODevice::... rather than QIODeviceBase::....
                      Alternatively did you try @J-Hilk's QIODevice::Append/Text without any extra #include?

                      R Offline
                      R Offline
                      RuWex
                      wrote on last edited by
                      #9

                      @JonB yes you right:)
                      I did QIODevice::Append and it is work well :-)
                      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