Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Qt Learning Summary (C Fish) path Parameter reference

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report