Qt how to open a file in current dir ? or what's wrong with this?

前端 未结 4 1166
遥遥无期
遥遥无期 2021-01-18 09:49

I\'m trying to open an xml file in the current location of the executable

        QString path = QDir::currentPath();
        path.append(\"/acc.xml\");
          


        
4条回答
  •  再見小時候
    2021-01-18 09:56

    I found this discussion while searching for a similar solution. I think that the most portable way of opening an external file that has a fixed name (and no dialogs and the user are involved) is to use the Resource System.

    In my case I created a new resource file with the prefix /config and added the file (called settings.xml). Inside the code, I don't need to use any path functions at all. I use the resource system instead. Thus a call like QFile file(":/config/settings.xml") works fine. Using QT creator 2.0.1 and QT 4.7 on Windows.

提交回复
热议问题