Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QFile and QTextStream Question
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED]QFile and QTextStream Question

Scheduled Pinned Locked Moved General and Desktop
24 Posts 3 Posters 20.2k Views 1 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.
  • IamSumitI Offline
    IamSumitI Offline
    IamSumit
    wrote on last edited by
    #4

    hii
    you didn't close the file so that's why you are not obtaining any value.
    just add a line at the end.
    @
    valueHSV.close();
    @

    Be Cute

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #5

      [quote author="IamSumit" date="1404195583"]hii
      you didn't close the file so that's why you are not obtaining any value.
      just add a line at the end.
      @
      valueHSV.close();
      @
      [/quote]

      Hi Sumit,

      after added in this line to close it,
      I make and run, the drag the slider in GUI, the txt file didn't have any value too, it is blank, i think i did wrongly, but i dont know what's wrong ....

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #6

        Replace your code with following and let me know if you see any debug output. If you don't see any debug output, for sure, you have file permission issue.

        @ int h_slide1 = ui->hueSlide1->value();
        QFile valueHSV("/home/pi/valueHSV/hsv.txt");
        if(!valueHSV.open(QIODevice::WriteOnly| QIODevice::Text)){
        qDebug() << "File not able to open" << endl;
        return;
        }
        QTextStream hsv(&valueHSV);
        hsv << h_slide1;
        qDebug() << "Value ="<<h_slide1
        valueHSV.close();
        @

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #7

          Hi
          Thanks for your reply,

          I use " make " command in LXTerminal,
          and i din see and debug output.

          i din see any "File not able to open" nor " Value = "

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #8

            i build and run after i do some change in Run Setting,
            it show: Cannot connect creatot comm socket /tmp/qt_temp.VO2750/stub-socket: No such file or directory
            Press

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #9

              after i uncheck the " Run in Terminal"
              it can Run but no any Application Output

              1 Reply Last reply
              0
              • IamSumitI Offline
                IamSumitI Offline
                IamSumit
                wrote on last edited by
                #10

                [quote]
                @ int h_slide1 = ui->hueSlide1->value();
                QFile valueHSV("/home/pi/valueHSV/hsv.txt");
                if(!valueHSV.open(QIODevice::WriteOnly| QIODevice::Text)){
                qDebug() << "File not able to open" << endl;
                return;
                }
                QTextStream hsv(&valueHSV);
                hsv << h_slide1;
                qDebug() << "Value ="<<h_slide1
                valueHSV.close();
                @
                [/quote]
                in order to get slider value you should write above code inside on_horizontalSlider_valueChanged() slot.

                Be Cute

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #11

                  hi Lam,

                  Could you please describe more?
                  I am too new to Qt ..

                  1 Reply Last reply
                  0
                  • IamSumitI Offline
                    IamSumitI Offline
                    IamSumit
                    wrote on last edited by
                    #12

                    Hii.
                    void QAbstractSlider::valueChanged ( int value ) [signal]
                    This signal is emitted when the slider value has changed, with the new slider value as argument.
                    http://qt-project.org/doc/qt-4.8/qabstractslider.html#valueChanged
                    This is the signal you need to connect with your slot .just like when you connect your QPushButton's clicked signal to it's Slot_clicked();
                    hope you know signal and slot
                    .

                    Be Cute

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #13

                      I try it now,
                      Feel like, i am going to fail my school Final Year Project ...

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #14

                        So, i need to create another .cpp and .h file for this?

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #15

                          because i am now writing this in a function
                          :
                          @void Dialog::getValue()
                          {
                          int h_slide1 = ui->hueSlide1->value();
                          QFile valueHSV("/home/pi/valueHSV/hsv.txt");
                          if(!valueHSV.open(QIODevice::WriteOnly| QIODevice::Text)){
                          qDebug() << "File not able to open" << endl;
                          return;
                          }
                          QTextStream hsv(&valueHSV);
                          hsv << h_slide1;
                          qDebug() << "Value ="<<h_slide1
                          valueHSV.close();
                          }@

                          1 Reply Last reply
                          0
                          • IamSumitI Offline
                            IamSumitI Offline
                            IamSumit
                            wrote on last edited by
                            #16

                            yes you can add another .h and .cpp file .inheriting QWidget class.

                            Be Cute

                            1 Reply Last reply
                            0
                            • ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #17

                              i need to use MainWindow or Dialog?

                              1 Reply Last reply
                              0
                              • ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #18

                                the function in .h file should be under signals?

                                1 Reply Last reply
                                0
                                • IamSumitI Offline
                                  IamSumitI Offline
                                  IamSumit
                                  wrote on last edited by
                                  #19

                                  hi
                                  you can take a reference from the following link
                                  http://www.codeprogress.com/cpp/libraries/qt/qProgressbarSetValueExample.php#.U7J--ZSSwb8

                                  [Edited: Remember it is an old example using 4.7]

                                  Be Cute

                                  1 Reply Last reply
                                  0
                                  • ? Offline
                                    ? Offline
                                    A Former User
                                    wrote on last edited by
                                    #20

                                    ermm.. this link not working..

                                    1 Reply Last reply
                                    0
                                    • ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by
                                      #21

                                      The example i can understand, but whn the slider move, can i save the current value to a txt file?

                                      1 Reply Last reply
                                      0
                                      • ? Offline
                                        ? Offline
                                        A Former User
                                        wrote on last edited by
                                        #22

                                        Hi Lam,

                                        I dont think your suggestion could work, i could not call ui into the function.

                                        1 Reply Last reply
                                        0
                                        • IamSumitI Offline
                                          IamSumitI Offline
                                          IamSumit
                                          wrote on last edited by
                                          #23

                                          [quote author="YDYD" date="1404207347"]ermm.. this link not working..[/quote]
                                          link is perfectly working.

                                          [quote author="YDYD" date="1404207723"]The example i can understand, but whn the slider move, can i save the current value to a txt file?[/quote]

                                          yes that is why this signal is given.

                                          [quote author="YDYD" date="1404207829"]Hi Lam,

                                          I dont think your suggestion could work, i could not call ui into the function.[/quote]

                                          the example does not use Qt designer Widget it is taking on run time.

                                          I think the problem is you have to understand the basics first like
                                          @
                                          creating .h and .cpp file inheriting QWidget/QMainWindow or Qdialog.
                                          SIGNAL and SLOT
                                          and many more thing.
                                          @

                                          Be Cute

                                          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
                                          • Unsolved