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 Offline
    S Offline
    swansorter
    wrote on 16 Jan 2021, 10:35 last edited by swansorter
    #1

    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));
    }
    
    M K 2 Replies Last reply 16 Jan 2021, 11:45
    0
    • S swansorter
      18 Jan 2021, 08:33

      @JonB yea

      J Offline
      J Offline
      JonB
      wrote on 18 Jan 2021, 08:57 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 19 Jan 2021, 04:46
      1
      • S swansorter
        16 Jan 2021, 10:35

        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));
        }
        
        M Offline
        M Offline
        mvuori
        wrote on 16 Jan 2021, 11:45 last edited by
        #2

        From your code we don't even know what mainsort is. Probably a file, but where it is and how you try to open it, remain mysteries. Perhaps there is relative path issue.

        S 1 Reply Last reply 16 Jan 2021, 13:03
        1
        • M mvuori
          16 Jan 2021, 11:45

          From your code we don't even know what mainsort is. Probably a file, but where it is and how you try to open it, remain mysteries. Perhaps there is relative path issue.

          S Offline
          S Offline
          swansorter
          wrote on 16 Jan 2021, 13:03 last edited by
          #3

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

          A 1 Reply Last reply 16 Jan 2021, 13:06
          0
          • S swansorter
            16 Jan 2021, 13:03

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

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 16 Jan 2021, 13:06 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 16 Jan 2021, 13:10
            1
            • A aha_1980
              16 Jan 2021, 13:06

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

              Regards

              S Offline
              S Offline
              swansorter
              wrote on 16 Jan 2021, 13:10 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

              J 1 Reply Last reply 16 Jan 2021, 13:32
              0
              • S swansorter
                16 Jan 2021, 13:10

                @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

                J Offline
                J Offline
                JonB
                wrote on 16 Jan 2021, 13:32 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 18 Jan 2021, 07:17
                1
                • J JonB
                  16 Jan 2021, 13:32

                  @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 18 Jan 2021, 07:17 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

                  J J 2 Replies Last reply 18 Jan 2021, 07:25
                  0
                  • S swansorter
                    18 Jan 2021, 07:17

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

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 18 Jan 2021, 07:25 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 18 Jan 2021, 07:37
                    1
                    • J jsulm
                      18 Jan 2021, 07:25

                      @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 18 Jan 2021, 07:37 last edited by
                      #9

                      @jsulm then where i can place ?

                      J 1 Reply Last reply 18 Jan 2021, 07:39
                      0
                      • S swansorter
                        18 Jan 2021, 07:37

                        @jsulm then where i can place ?

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 18 Jan 2021, 07:39 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 18 Jan 2021, 08:03
                        3
                        • S swansorter
                          18 Jan 2021, 07:17

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

                          J Offline
                          J Offline
                          JonB
                          wrote on 18 Jan 2021, 07:40 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 18 Jan 2021, 08:02
                          0
                          • J JonB
                            18 Jan 2021, 07:40

                            @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 18 Jan 2021, 08:02 last edited by
                            #12

                            @JonB getting error 5

                            J 1 Reply Last reply 18 Jan 2021, 08:06
                            0
                            • J jsulm
                              18 Jan 2021, 07:39

                              @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 18 Jan 2021, 08:03 last edited by
                              #13

                              @jsulm i will check

                              1 Reply Last reply
                              0
                              • S swansorter
                                18 Jan 2021, 08:02

                                @JonB getting error 5

                                J Offline
                                J Offline
                                JonB
                                wrote on 18 Jan 2021, 08:06 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 18 Jan 2021, 08:33
                                0
                                • J JonB
                                  18 Jan 2021, 08:06

                                  @swansorter said in QT FILE OPERATION:

                                  @JonB getting error 5

                                  That is what QFile::errorString() reports?

                                  S Offline
                                  S Offline
                                  swansorter
                                  wrote on 18 Jan 2021, 08:33 last edited by
                                  #15

                                  @JonB yea

                                  J 1 Reply Last reply 18 Jan 2021, 08:57
                                  0
                                  • S swansorter
                                    16 Jan 2021, 10:35

                                    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));
                                    }
                                    
                                    K Offline
                                    K Offline
                                    KroMignon
                                    wrote on 18 Jan 2021, 08:45 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 19 Jan 2021, 04:47
                                    0
                                    • S swansorter
                                      18 Jan 2021, 08:33

                                      @JonB yea

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 18 Jan 2021, 08:57 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 19 Jan 2021, 04:46
                                      1
                                      • J JonB
                                        18 Jan 2021, 08:57

                                        @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 19 Jan 2021, 04:46 last edited by
                                        #18

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

                                        1 Reply Last reply
                                        1
                                        • K KroMignon
                                          18 Jan 2021, 08:45

                                          @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 19 Jan 2021, 04:47 last edited by
                                          #19

                                          @KroMignon thank you sir for your information

                                          1 Reply Last reply
                                          0

                                          3/19

                                          16 Jan 2021, 13:03

                                          topic:navigator.unread, 16
                                          • Login

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