qfile

QFile won't open the file

旧城冷巷雨未停 提交于 2020-01-04 02:02:07
问题 I have a program that I basically stole from the Qt website to try to get a file to open. The program refuses to open anything I am confused as to why. I have looked for lots of documentation but found nothing can you please explain why it does not work. #include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QTextStream> #include <QString> MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { QFile file("C:/n.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice:

QSocketNotifier and QFile::readAll()

十年热恋 提交于 2019-12-25 03:15:26
问题 Currently working on the GPIOs of a SBC (Olimex A20), I have a problem with QSocketNotifier. On my GPIOs, I'm using a pin with interruption abilities (For those who want to know more : https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals ) and a QSocketNotifier to monitor the changes. That's my class for interruptions : OLinuXinoGPIOEdge::OLinuXinoGPIOEdge(int num) : m_gpioNumber(num), m_value(false), m_direction(IN) { this->exportGPIO(); // equivalent to 'echo num > export'

How do you serialize a QMap?

人盡茶涼 提交于 2019-12-22 13:08:08
问题 I'm trying to learn how to serialize QMap objects in windowed applications, using this code: #include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QString> #include <QDataStream> #include <QMap> #include <QDebug> void write () { QString filename = "Z:/snippets.txt"; QFile myFile (filename); if (!myFile.open(QIODevice::WriteOnly)) { qDebug() << "Could not write " << filename; return; } QMap<QString,QString> map; map.insert("one","this is 1"); map.insert("two","this is 2

Progress bar with QFile::copy()?

放肆的年华 提交于 2019-12-19 17:46:23
问题 I'm making a program which copies files in Qt. I want to know how can I use QProgressBar with bool QFile::copy(const QString & fileName, const QString & newName) . Is this even possible with copy function? Can the process of copying be paused? 回答1: You can't do this using the static QFile::copy() method. As Maciej stated before you need to write your own class. It should use two QFile objects, one for reading one for writing. Transfer the data in portions (e.g 1% of the entire file size) and

Convert QFile to FILE*

回眸只為那壹抹淺笑 提交于 2019-12-19 17:45:13
问题 Is there another way to convet QFile to File? Different than this: QFile myFile("goforward.raw"); int FileDescriptor = myFile.handle(); FILE* fh = fdopen(FileDescriptor, "rb"); 回答1: I think you already know that you have the various open , read , etc. methods in QFile. That said, if the file is not opened, then the handle method returns an error. QFile myFile("goforward.raw"); myFile.open(QIODevice::ReadOnly); int fileHandle = myFile.handle(); After that, you might reopen it with: FILE* fh =

Qt cannot cannot create/write to C:\

风格不统一 提交于 2019-12-19 08:04:13
问题 I am writing a Qt program (4.7 for windows 7 initially) that requires writing to the installed directory (C:\Program Files...). No files are being created when I try to write to a location that would be "protected" (program files, C:\ etc). However, QFile is not giving me any error code (error() is returning 0 which means it worked fine). Here is a code snippit that I am using that is not working. I am closing the file its just much later in the program. QApplication a(argc, argv); // Setting

Qt5, symbolic link to a folder

Deadly 提交于 2019-12-11 13:30:23
问题 A dupe-ish question of this question, which (possibly) has got an outdated answer, as I can't get it to work in Qt5. I wish to create a symbolic link to a folder for a result similar to QFile::link() . Given that QDir doesn't have an equivalent function, QProcess (or an external library) seems like the way out if I'm up to snuff. How would this be managed in Qt5? Big thanks in advance. 回答1: There are shortcuts and hardlinks on Windows. I think mklink refers to hardlinks. It works for

Qt - How to count number of line in .txt file

旧巷老猫 提交于 2019-12-11 11:09:41
问题 I want to count number of line in text file, so i can convert it to two dimensional array The text file should be like this 20 30 78 1000 .... .... and source code using QFile to access file QFile file("c:/Qt/in.txt"); file.open(QIODevice::ReadOnly); //| QIODevice::Text) y = linecount/5; QString line[y][5]; QTextStream in(&file); for (int k=0;k<=y;k++) { for (int x=0;x<=4;x++) { line[i][x] = in.readLine(); } } 回答1: Your Question is not clear, and also some parameters in your code. For

QFile::QFile function --> Error: QFile :: QFile (const QFile &) 'is private

青春壹個敷衍的年華 提交于 2019-12-11 04:04:02
问题 In one of my methods I need a QFile Object: void GUIsubclassKuehniGUI::LoadDirectory() { QString loadedDirectory = QFileDialog::getExistingDirectory(this, "/home",tr("Create Directory"), QFileDialog::DontResolveSymlinks); ui.PathDirectory -> setText(loadedDirectory); QFileInfo GeoDat1 = loadedDirectory + "/1_geo.m4"; QFileInfo GeoDat2 = loadedDirectory + "/2_geo.m4"; QString Value; if (GeoDat1.exists() == true) { QFile GEO = (loadedDirectory + "/1_geo.m4"); // ERROR LINE HERE! if(GEO.open

Reading from a QFile in different thread

扶醉桌前 提交于 2019-12-08 13:19:28
What would be the optimal way of reading from a QFile that resides in a different thread than the one I want to read from? Consider: class AFile : public QObject { Q_OBJECT public: AFile(const QString &name, QObject *parent = Q_NULLPTR) : QObject(parent), m_File(name) { m_File.open(QIODevice::ReadWrite); } public slots: void write(const QByteArray &data, qint64 pos) { m_File.seek(pos); m_File.write(data); } private: mutable QFile m_File; }; class AData : public QObject { Q_OBJECT public: using QObject::QObject; void save(const QByteArray &data) { emit saveData(data, 0); } signals: void