Justin Tennant
Justin Tennant

Reputation: 63

How to use relative paths in a Qt-based Autodesk Maya plug-in?

I'm trying to build a plug-in for Maya 2016 using Qt and I'm not sure how to use a relative path to reference a specific asset I need.

Inside my code for my plug-in, I'm using QUiLoader and QFile to load a my_ui.ui file which contains my pre-designed dialog window made from Qt Designer:

QUiLoader   loader;
QFile       file("my_ui.ui");

file.open(QFile::ReadOnly);
fForm = loader.load(&file, this);
file.close();

The my_ui.ui is in the same directory as my compiled plugin.so plug-in (I'm using Linux).

Any sort of relative pathing (./, .) gives me the location to wherever Maya is ran from, understandably. But is there a way to get the path of my .so plugin itself?

Upvotes: 0

Views: 323

Answers (1)

Justin Tennant
Justin Tennant

Reputation: 63

I figured out the solution on my own:

In my Qt Project .pro file, I added the following lines:

FORMS += my_ui.ui
RESOURCES += my_ui.qrc

And I added a new file, my_ui.qrc, which contained this:

<!DOCTYPE RCC><RCC version="1.0">
<qresource>
    <file>my_ui.ui</file>
</qresource>
</RCC>

The .qrc resource collection file lists the dependencies of my application, and adding the RESOURCES line to my .pro file tells qmake to compile my resource files into the final binary.

Then in my application, I modified my QFile constructor to use the resource path:

QFile       file(":/my_ui.ui");

I got this info from looking at the Maya devkit Qt examples and the Qt Resource System documentation (http://doc.qt.io/qt-5/resources.html).

Upvotes: 1

Related Questions