Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Question regarding QStandardPaths
Qt 6.11 is out! See what's new in the release blog

Question regarding QStandardPaths

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 904 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amanill
    wrote on last edited by
    #1

    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");
    
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      amanill
      wrote on last edited by
      #7

      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);

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        What means 'does not work'?
        Did you output the returned location to see if it fits your expectations?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amanill
          wrote on last edited by
          #3

          it does not compile, returns this
          C:\Users\Aaron\Documents\FirmwareBuilder\file.cpp:36: error: invalid operands to binary expression ('QStringList' and 'const char *')

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            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

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              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.tfu to it.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Ah, stupid me... read 'QString', not 'QStringList'. Sorry
                @SGaist is right :)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  amanill
                  wrote on last edited by
                  #7

                  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);

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved