QT FILE OPERATION
-
@jsulm then where i can place ?
@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. -
@JonB
1.file creation not happening
2.located in opt/QtE_demo /
3.i wanted place file where my application file is located@swansorter said in QT FILE OPERATION:
1.file creation not happening
What did you do about printing
QFile::error
/errorString()
if file open fails? -
@swansorter said in QT FILE OPERATION:
1.file creation not happening
What did you do about printing
QFile::error
/errorString()
if file open fails?@JonB getting error 5
-
@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.@jsulm i will check
-
@JonB getting error 5
@swansorter said in QT FILE OPERATION:
@JonB getting error 5
That is what
QFile::errorString()
reports? -
@swansorter said in QT FILE OPERATION:
@JonB getting error 5
That is what
QFile::errorString()
reports?@JonB yea
-
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)); }
@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? -
@JonB yea
@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 exampleQStandardPaths::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.
-
@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 exampleQStandardPaths::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.
@JonB thank very much.
i created separate folder for file operation in home location -
@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?@KroMignon thank you sir for your information