I'm stuck with a problem concerning udev symlink property.
I just set udev rules so that my TTL-232R USB device has a symlink name.
However, I don't know how to extract this symlink name on my Qt project (which is actually not originally mine but someone else's). In the first place, the code gets the portname using libudev library and function udev_device_get_devnode(struct udev_device), which returns ttyUSB0. But I don't want the absolute name, just the symlink name. Unfortunately, I can't seem to find some similar function in the libudev library to get the symlink name i just set with udev rules.
Is there another library or way to do that? I'm a bit lost..
Regards,
try QString QFile::symLinkTarget() const
#include <QFile>
...
QFile file('/sym/link/target');
qDebug() << file.symLinkTarget();
...
Related
I'm interested in importing an external SQLite database to my project.
When using the QT Quick Local Storage:
LocalStorage.openDatabaseSync("QQmlExampleDB", "1.0", "The Example QML SQL!", 1000000);
The problem is that, the program generates a NEW database, and if it's possible I'm interested in open an existing database.
Any idea?
Thank you very much!
Thanks all of you, with the information you have got me I could solve my problem, all the things I have had to do are:
First of all in main.cpp I set my offline Storage Path:
engine.setOfflineStoragePath(QString("./"));
Then I also add this code:
QDir dir("./Databases");
if (!dir.exists()) {
dir.mkpath(".");
}
QString new_name = QString(QCryptographicHash::hash(("nameofthecopiedDB"),QCryptographicHash::Md5).toHex());
QFile file(":/SQLite/nameofsourceDB.sqlite");
file.copy("./Databases/" + new_name + ".sqlite");
file.close();
Since I have the DB I would to use in my project in SQLite folder from my resources (:, indicates resources).
And then, in QML file, the openDatabaseSync() function:
basedades = Sql.LocalStorage.openDatabaseSync('nameofthecopiedDB',"1.0","Els meus entrenaments",1000000,"QSQLITE")
Thank you!
openDatabaseSync searches or creates dbs in the directory used for storing offline data.
That directory is identified by the data member offlineStoragePath of the QQmlEngine class.
To change it, you can use the the member method setOfflineStoragePath (see here for further details).
The first argument for openDatabaseSync is:
The name of the database passed to openDatabase()
See here for further details.
I'm trying to download a file in Qt5, but the file must not be located on the HDD after download.
To clarify> My app will use a downloaded file to update some firmware, and I don't want the downloaded update to remain on the user's hard drive because it could get stolen.
So, I'm trying to make a QFile from QNetworkReply* but without saving it to some path on a hard drive.
I'm downloading a file using QNetworkAccessManager and storing the data into QNetworkReply. I always used to make a QFile with QNetworkReply*, but now I can't do that.
I have found the QTemporaryFile class where a file gets removed right after using it, but that still leaves user with some options of finding the file later.
I tried typecasting that QNetworkReply* as a QFile, but didn't manage to get that to work, seems like QFile can't be without a path on HDD.
Does anyone have any ideas how to do this, and how?
Thanks everyone.
Again not sure your intended end use case but since your data is small enough to hold in memory you can use a QByteArray or QBuffer and write into it from your QNetworkReply. QBuffer provides a QIODevice interface for the QByteArray so it may be a bit easier for you to work with.
Make sure to open the QBuffer for read/write. See the simple example below from the Qt documentation, http://doc.qt.io/qt-5/qbuffer.html#details, below:
QBuffer buffer;
char ch;
buffer.open(QBuffer::ReadWrite);
buffer.write("Qt rocks!");
buffer.seek(0);
buffer.getChar(&ch); // ch == 'Q'
buffer.getChar(&ch); // ch == 't'
buffer.getChar(&ch); // ch == ' '
buffer.getChar(&ch); // ch == 'r'
That should allow you to read back the data and use as required without creating a file on the system.
I am making a project in QT Creator 2.6. I am promoting a QWidget subclass called cPlotter, but when I try to compile the project, it fails because it cannot find the file cplotter.h. I figured out that this is because the file “ui_mainwindow.h” updates automatically including the file cplotter.h within brackets instead of quotes.
So, ui_mainwindow.h updates like:
#include < cplotter.h >
but it should be:
#include “cplotter.h”
So, it is very annoying to edit by hand every time I change something on the GUI.
Anyone knows a solution for this?
INCLUDEPATH += $$PWD
(or where cplotter.h)
I have the following issue: I create a QFileSystemWatcher and it runs and works nicely on Linux, but no way on Windows 7. Can you spot anything in the code that might make it not to work?
Thx.
Here is the code to initialize it:
mConfigChangeWatcher = new QFileSystemWatcher();
mConfigChangeWatcher->addPath(config_file_name);
QObject::connect(mConfigChangeWatcher,
SIGNAL(fileChanged(QString)),
this,
SLOT(configFileChanged(QString)));
and this is supposed to be the slot getting the work done:
void MyClass::configFileChanged(const QString &file)
{
qDebug() << "Changed: " << file ;
}
When you check if the file is added to the watcher using QFileSystemWatcher::files() method after the first modification in the file do you get the correct list?
I was with the issue that some applications, when modifing a file, delete the old file from the system and write it again.
Note that QFileSystemWatcher stops monitoring files once they have been renamed or removed from disk, and directories once they have been removed from disk.
I was using QFileSystemWatcher to watch an image file edited by Photoshop. Somehow the file gets removed from the list of files being watched.
I had the same problem and solved it very fast.
Within the slot that manages the fileChanged signal I noted the path disappears from files(). I simply make a check and re-add it if necessary
if (! watcher_.files().contains(path))
{
watcher_.addPath(path);
}
I hope this helps
Fabio
I'm trying to use translation files. I went through all the procedures:
created ts file, translated it, but when I run the application, the language is still the same as before.
I worked on the Nokia example, just like in the instructions.
What could be my problem?
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTranslator* translator=new QTranslator(0);
if(QFile::exists("hellotr_la.qm"))
qWarning("failed-no file");
if(! translator->load("hellotr_la.qm"))
qWarning("failed loading"); //the warning appears ****
app.installTranslator(translator);
}
Where are the .qm files located? Your code is attempting to load the file from the current working directory, which can be anything during runtime. Specify a directory path in the call to QTranslator::load:
QTranslator* translator = new QTranslator();
if (translator->load("hellotr_la", "/path/to/folder/with/qm/files")) {
app.installTranslator(translator);
}
Translations can be loaded from Qt resources, so it is a good idea to bundle them inside your executables. Then you would load them somewhat like this:
QTranslator* translator = new QTranslator();
if (translator->load("hellotr_la", ":/resources/translations")) {
app.installTranslator(translator);
}
The answer was already given in a comment, but I want to point it out clearly.
The first warning uses a wrong condition:
if(QFile::exists("hellotr_la.qm"))
qWarning("failed-no file");
It should be:
if(!QFile::exists("hellotr_la.qm"))
qWarning("failed-no file");
Since you only saw the second warning, but not the first one, the problem is indeed that the file was not found. Make sure that the working directory is what you expect it to be or (better) use the resource system as explained by andref.
Based on the example, can you simply try this :
QTranslator translator;
translator.load("hellotr_la");
app.installTranslator(&translator);
Hope it will fix your problem !
Note 1 : No pointer here.
Note 2 : No extension in your filename.