qfile

Reading from a QFile in different thread

限于喜欢 提交于 2019-12-08 04:13: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:

QT - QFile copy operation extremely slow

為{幸葍}努か 提交于 2019-12-08 03:08:12
问题 I'm developing an application that needs to copy lots of files from one folder to another, using QT (5.6.1) For doing this, I've been using the QFile::copy() method. This works well, except for one thing: it is extremely slow. Takes more than twice the time that the same copy operation takes using windows explorer. Wondering why this was, I dug into the QT source code, and I found this in qfile.cpp , which looks relevant: char block[4096]; qint64 totalRead = 0; while(!atEnd()) { qint64 in =

QT - QFile copy operation extremely slow

半城伤御伤魂 提交于 2019-12-06 14:14:27
I'm developing an application that needs to copy lots of files from one folder to another, using QT (5.6.1) For doing this, I've been using the QFile::copy() method. This works well, except for one thing: it is extremely slow. Takes more than twice the time that the same copy operation takes using windows explorer. Wondering why this was, I dug into the QT source code, and I found this in qfile.cpp , which looks relevant: char block[4096]; qint64 totalRead = 0; while(!atEnd()) { qint64 in = read(block, sizeof(block)); if (in <= 0) break; totalRead += in; if(in != out.write(block, in)) { close(

How do you serialize a QMap?

老子叫甜甜 提交于 2019-12-06 09:31:42
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"); map.insert("three","this is 3"); QDataStream out (&myFile); out.setVersion(QDataStream::Qt_5_3);

How to write and read to/from a QResource file in Qt 5?

孤者浪人 提交于 2019-12-04 05:17:25
问题 It's strange, I add desired file into the resources via Add Existing Files... , the file is there. I run qmake ("Build->Run qmake") to make the file available. The first issue: I can't write anything into the file from output terminal! But when I manually write into the file, the output terminal shows the change every time I run it. Second issue: it still says QIODevice::read: device not open ! Here's my code: #include <QCoreApplication> #include <QDebug> #include <QFile> #include <QString>

How to move a file to another existing directory in Qt

雨燕双飞 提交于 2019-12-04 04:14:52
问题 I am a beginner in Qt, one part of my project is moving a existing file to another existing directory? Can someone gives me a specific example? I am not sure whether I should use Qfile::rename(). I try write like this QDir::rename("/home/joshua/test.txt","/home/joshua/test/test_c.txt"); but the error is cannot call member function 'bool QDir::rename(const QString&, const QString&)' without object QDir::rename("/home/joshua/test.txt","/home/joshua/test/test_c.txt"); ^ Sorry guys, all are my

How to write and read to/from a QResource file in Qt 5?

北战南征 提交于 2019-12-02 05:27:33
It's strange, I add desired file into the resources via Add Existing Files... , the file is there. I run qmake ("Build->Run qmake") to make the file available. The first issue: I can't write anything into the file from output terminal! But when I manually write into the file, the output terminal shows the change every time I run it. Second issue: it still says QIODevice::read: device not open ! Here's my code: #include <QCoreApplication> #include <QDebug> #include <QFile> #include <QString> #include <QTextStream> #include <iostream> void wFile(QString Filename) { QFile nFile(Filename);

os.walk analogue in PyQt

﹥>﹥吖頭↗ 提交于 2019-12-02 01:09:23
问题 Before I can continue to implement recursive dir/file search with some filtering for some tasks I want to know if Qt/PyQt has analogue of os.walk . Main app is a GUI app in PyQt4 and all text fields in a QString s and path objects (files, directories) uses QFile , QDir , QFileinfo for manipulations. As analogue I mean fast and convenient recursive fs-tree traversal tool. Should I use os.walk or something much faster and more informative? PS. Maybe this can help me but I'm not sure if this

os.walk analogue in PyQt

戏子无情 提交于 2019-12-01 22:36:48
Before I can continue to implement recursive dir/file search with some filtering for some tasks I want to know if Qt/PyQt has analogue of os.walk . Main app is a GUI app in PyQt4 and all text fields in a QString s and path objects (files, directories) uses QFile , QDir , QFileinfo for manipulations. As analogue I mean fast and convenient recursive fs-tree traversal tool. Should I use os.walk or something much faster and more informative? PS. Maybe this can help me but I'm not sure if this more efficient than os.walk . Should I use os.walk or something much faster and more informative? There is

Progress bar with QFile::copy()?

半世苍凉 提交于 2019-12-01 17:18:09
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? 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 emit a progress signal after each portion. You can connect this signal to a progress dialog. If you need