Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Qt Learning Summary (C Fish) path Parameter reference

Shulou Source: shulou.com Published: 2022-06-02 19:07:17 09月30日 Update

1. Reference relative path:

For example: QCursor cursor (QPixmap ("1.png"))

Problem: you will find that the reference failed because the relative path starts to find the file from the current working directory. You can get the current working directory through the following functions:

Bool QDir::setCurrent (const QString & path) [static]

Then you will find that the current working directory is C:\ Users\ Administrator, which does not match. So you can consider resetting the current working directory, and another problem, because Qt puts the project directory and the program directory in two places, for example:

Program directory: C:\ Users\ Administrator\ Desktop\ QT\ build-Qt-Project-05-unknown-Debug

Project directory: C:\ Users\ Administrator\ Desktop\ QT\ Qt-Project-05

As for the program directory, you can actually get it by calling the following function:

QString QCoreApplication::applicationDirPath () [static]

Well, now that we have the program directory, we can set the current working directory to the program directory, for example:

QDir::setCurrent (QCoreApplication::applicationDirPath ())

two。 Reference absolute path:

For example:

QCursor cursor (QPixmap ("C://Users//Administrator//Desktop//QT//build-Qt-Project-05-unknown-Debug//debug//1.png"))

After testing, both'/ 'and'\ 'are valid.

3. Reference the resource file:

When the resource file is added, and the prefix is set to'/'. Then you can quote it directly, for example:

QCursor cursor (QPixmap (": / resource/1.png"))

Note that the': 'character is added before it.

Tags: Directories programs work paths files functions can pass engineering resources problems valid two prefixes places characters this is testing parameters learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info NVidia MySQL Redmi