Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QT FILE OPERATION
Forum Updated to NodeBB v4.3 + New Features

QT FILE OPERATION

Scheduled Pinned Locked Moved Solved Mobile and Embedded
19 Posts 6 Posters 1.8k 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.
  • S swansorter

    @mvuori mainsort is file name,it is in poject directory path

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @swansorter but the executable is in the build directory, not the project directory.

    Regards

    Qt has to stay free or it will die.

    S 1 Reply Last reply
    1
    • aha_1980A aha_1980

      @swansorter but the executable is in the build directory, not the project directory.

      Regards

      S Offline
      S Offline
      swansorter
      wrote on last edited by
      #5

      @aha_1980 In pc it working fine .In buid directory executable is there and my mainsort file also there only.

      but it is not happening in my board

      JonBJ 1 Reply Last reply
      0
      • S swansorter

        @aha_1980 In pc it working fine .In buid directory executable is there and my mainsort file also there only.

        but it is not happening in my board

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

        @swansorter
        What is not happening on board? Where is the file located, and how are you expecting it to be picked up with the path you specify? What are you expecting QDir::current() to be in each case? Why don't you at least output it in each case so they you/we know where it is looking? And why doesn't your code give any indication to anybody if it fails to open the file? And no call to QFile::error/errorString().

        Also, personally, I would not try to access QDir::current() at global scope. It will presumably be evaluated prior to whatever QApplication you create. Wouldn't it be safer to have it execute that after creating the application? There is no need to have those two variables as globals.

        S 1 Reply Last reply
        1
        • JonBJ JonB

          @swansorter
          What is not happening on board? Where is the file located, and how are you expecting it to be picked up with the path you specify? What are you expecting QDir::current() to be in each case? Why don't you at least output it in each case so they you/we know where it is looking? And why doesn't your code give any indication to anybody if it fails to open the file? And no call to QFile::error/errorString().

          Also, personally, I would not try to access QDir::current() at global scope. It will presumably be evaluated prior to whatever QApplication you create. Wouldn't it be safer to have it execute that after creating the application? There is no need to have those two variables as globals.

          S Offline
          S Offline
          swansorter
          wrote on last edited by
          #7

          @JonB
          1.file creation not happening
          2.located in opt/QtE_demo /
          3.i wanted place file where my application file is located

          jsulmJ JonBJ 2 Replies Last reply
          0
          • S swansorter

            @JonB
            1.file creation not happening
            2.located in opt/QtE_demo /
            3.i wanted place file where my application file is located

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @swansorter said in QT FILE OPERATION:

            opt/QtE_demo /

            Do you mean /opt/QtE_demo/? If so /opt is not writeable by normal users.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            1
            • jsulmJ jsulm

              @swansorter said in QT FILE OPERATION:

              opt/QtE_demo /

              Do you mean /opt/QtE_demo/? If so /opt is not writeable by normal users.

              S Offline
              S Offline
              swansorter
              wrote on last edited by
              #9

              @jsulm then where i can place ?

              jsulmJ 1 Reply Last reply
              0
              • S swansorter

                @jsulm then where i can place ?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @swansorter User data is usually stored in user home directory.
                Check https://doc.qt.io/qt-5/qstandardpaths.html to see how to get various standard locations.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply
                3
                • S swansorter

                  @JonB
                  1.file creation not happening
                  2.located in opt/QtE_demo /
                  3.i wanted place file where my application file is located

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

                  @swansorter said in QT FILE OPERATION:

                  1.file creation not happening

                  What did you do about printing QFile::error/errorString() if file open fails?

                  S 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @swansorter said in QT FILE OPERATION:

                    1.file creation not happening

                    What did you do about printing QFile::error/errorString() if file open fails?

                    S Offline
                    S Offline
                    swansorter
                    wrote on last edited by
                    #12

                    @JonB getting error 5

                    JonBJ 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @swansorter User data is usually stored in user home directory.
                      Check https://doc.qt.io/qt-5/qstandardpaths.html to see how to get various standard locations.

                      S Offline
                      S Offline
                      swansorter
                      wrote on last edited by
                      #13

                      @jsulm i will check

                      1 Reply Last reply
                      0
                      • S swansorter

                        @JonB getting error 5

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

                        @swansorter said in QT FILE OPERATION:

                        @JonB getting error 5

                        That is what QFile::errorString() reports?

                        S 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @swansorter said in QT FILE OPERATION:

                          @JonB getting error 5

                          That is what QFile::errorString() reports?

                          S Offline
                          S Offline
                          swansorter
                          wrote on last edited by
                          #15

                          @JonB yea

                          JonBJ 1 Reply Last reply
                          0
                          • S swansorter

                            sir
                            I am working on Nano pc t2 board
                            pc os ubuntu 16.04
                            Nano pc t2 OS 16.04 ubuntu
                            i am able to do all the file operation (open read close and write )in pc,but if i cross compile and run it on my kit(nano pc t2) file operation are not working

                            #include "mainwindow.h"
                            #include "ui_mainwindow.h"
                            #include<qfile.h>
                            #include <QTextStream>
                            #include <QtCore>
                            QFile mainsort(QDir::current().path()+"/ms.csv");
                            QByteArray temp1;
                            MainWindow::MainWindow(QWidget *parent) :
                                QMainWindow(parent),
                                ui(new Ui::MainWindow)
                            {
                                ui->setupUi(this);
                            }
                            
                            MainWindow::~MainWindow()
                            {
                                delete ui;
                            }
                            
                            void MainWindow::on_pushButton_pressed()
                            {
                            
                               if ( mainsort.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text) )
                               {
                                    QTextStream out(&mainsort);
                                   out << "something";
                                   ui->label->setText("WRitten");
                               }
                               mainsort.close();
                            
                            }
                            
                            void MainWindow::on_pushButton_2_pressed()
                            {
                                QCoreApplication::quit();
                            }
                            
                            void MainWindow::on_pushButton_3_pressed()
                            {
                                  mainsort.open(QIODevice::ReadOnly);
                                  temp1=mainsort.readAll();
                                  mainsort.close();
                                  ui->label->setText( QString::fromUtf8(temp1));
                            }
                            
                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by KroMignon
                            #16

                            @swansorter said in QT FILE OPERATION:

                            QFile mainsort(QDir::current().path()+"/ms.csv");

                            I don't think this is a good idea to do this, at least with a global variable!
                            Have you checked, on the Nano pc on which path you tried to write?
                            Have you checked the directory is writable / the application is allowed to write there?

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            S 1 Reply Last reply
                            0
                            • S swansorter

                              @JonB yea

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

                              @swansorter
                              Slightly strange that you just get a number, and it seems to mean I/O Error, which is also a touch strange.

                              Nevertheless, @jsulm has told you above what you need to use. Pick a QStandardPaths suitable for the user to have write permission, for example QStandardPaths::HomeLocation.

                              3.i wanted place file where my application file is located

                              This is a bad idea. The application file/executable is likely to be placed in a directory to which the user does not have write access, and anyway it's not a good place for data files.

                              S 1 Reply Last reply
                              1
                              • JonBJ JonB

                                @swansorter
                                Slightly strange that you just get a number, and it seems to mean I/O Error, which is also a touch strange.

                                Nevertheless, @jsulm has told you above what you need to use. Pick a QStandardPaths suitable for the user to have write permission, for example QStandardPaths::HomeLocation.

                                3.i wanted place file where my application file is located

                                This is a bad idea. The application file/executable is likely to be placed in a directory to which the user does not have write access, and anyway it's not a good place for data files.

                                S Offline
                                S Offline
                                swansorter
                                wrote on last edited by
                                #18

                                @JonB thank very much.
                                i created separate folder for file operation in home location

                                1 Reply Last reply
                                1
                                • KroMignonK KroMignon

                                  @swansorter said in QT FILE OPERATION:

                                  QFile mainsort(QDir::current().path()+"/ms.csv");

                                  I don't think this is a good idea to do this, at least with a global variable!
                                  Have you checked, on the Nano pc on which path you tried to write?
                                  Have you checked the directory is writable / the application is allowed to write there?

                                  S Offline
                                  S Offline
                                  swansorter
                                  wrote on last edited by
                                  #19

                                  @KroMignon thank you sir for your information

                                  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