Question regarding QStandardPaths
-
I am trying to use QStandardPaths to output a file to the desktop regardless of OS, but can't figure out how to include the file name.
I know i can find the desktop with
(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation));I tried the following but it does not work
QFile result((QStandardPaths::standardLocations(QStandardPaths::DesktopLocation))+"/mergedfile.rfu"); -
Here is how I solved what I was attempting to do, I doubt it's the most efficient way, but I am new to both QT and C++ and it works so I am satisfied for now:
QStringList location = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation);
QString loc = location[0];
loc = loc + QString("/merged.rfu");
QFile result(loc); -
What means 'does not work'?
Did you output the returned location to see if it fits your expectations? -
So it's a plain compiler error and has nothing to do with QStandardPaths at all...
You've defined 'QT_NO_CAST_FROM_ASCII' in your project and now trying to add a char* to a QString which is forbidden due to this define: http://doc.qt.io/qt-5/qstring.html#QT_NO_CAST_FROM_ASCII -
Hi,
As the message suggest you are trying to add a char * to a QStringList.
QStandardPaths::standardLocations returns a QStringList. So you should take the first element on that list and then add
/mergedfile.tfuto it. -
Ah, stupid me... read 'QString', not 'QStringList'. Sorry
@SGaist is right :) -
Here is how I solved what I was attempting to do, I doubt it's the most efficient way, but I am new to both QT and C++ and it works so I am satisfied for now:
QStringList location = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation);
QString loc = location[0];
loc = loc + QString("/merged.rfu");
QFile result(loc);