QT resource access

QT resource access

NICOLAS_LEONARD
Explorer Explorer
4,993 Views
5 Replies
Message 1 of 6

QT resource access

NICOLAS_LEONARD
Explorer
Explorer

Has anyone had success in using Qt resources in a C++ max plug-in?

 

I have no problem creating Qt UI such as a QDialog and bringing it up.  And if I create QIcons from an external image file, the icons are created as expected.  But then I tried to move the icon image files to qt resources and that unexpectedly fails.

 

I created a qrc resource file, added a few images to use in icons.  The qrc file gets rcc'd, which generates a cpp file, which gets compiled, and yet the attempts to read in the image files I placed in there just fail.  The content of my project resource file just isn't available to my plug-in.

 

Any Qt-in-max experts?

0 Likes
Accepted solutions (1)
4,994 Views
5 Replies
  • qt
Replies (5)
Message 2 of 6

NICOLAS_LEONARD
Explorer
Explorer

Ok I can give some additional details.

 

First regarding project set-up.

 

I am using Qt UI for dialogs and such without problems.

I added a .qrc file named QtResource.qrc to the project containing a couple of image files:
Qrc.jpg
I can see that file getting rcc'ed, generating a file named qrc_QtResource.cpp, which does get compiled:
1>------ Build started: Project: DrivenController, Configuration: Debug x64 ------
1>Rcc'ing QtResource.qrc...
[...]
1>DllEntry.cpp
1>qrc_QtResource.cpp
1> Creating library C:\Users\Nicolas\source\repos\3ds max\2021\LinkController\LinkController\\obj\x64\Debug\\DrivenController.lib and object C:\Users\Nicolas\source\repos\3ds max\2021\LinkController\LinkController\\obj\x64\Debug\\DrivenController.exp
1>DrivenController.vcxproj -> C:\Program Files\Autodesk\3ds Max 2021\Plugins\DrivenController.dlc
1>C:\Users\Nicolas\source\repos\3ds max\2021\LinkController\LinkController\obj\x64\Debug\DrivenController.dlc.muiLanguage neutral file successfully created at "C:\Users\Nicolas\source\repos\3ds max\2021\LinkController\LinkController\obj\x64\Debug\DrivenController.dlc.ln".
1>MUI file successfully created at "C:\Users\Nicolas\source\repos\3ds max\2021\LinkController\LinkController\obj\x64\Debug\DrivenController.dlc.mui".
1>Done building project "DrivenController.vcxproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

 

Now regarding using the Qt resources.

 

If I use an absolute path on an external image file, i.e.:

QIcon mutedIcon("<absolute path>\\Images\\muted.png");

the icon will be created and show up as expected.

But if I try to read it from the resource file:

QIcon mutedIcon(":/DrivenController/Images/muted.png");

the icon is null.

 

I tried to list the content of the Qt file system with this code:

QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.next();
}


There are many entries, including max-specific content, like
":/qt-project.org/styles/commonstyle"
":/qt-project.org/styles/commonstyle/images"
":/qt-project.org/styles/commonstyle/images/networkdrive-16.png"
":/qt-project.org/styles/commonstyle/images/networkdrive-32.png"
":/qt-project.org/styles/commonstyle/images/dvd-16.png"
":/qt-project.org/styles/commonstyle/images/cdr-16.png"
":/Icons/CommandPanel"
":/Icons/CommandPanel/Utilities"
":/Icons/CommandPanel/Utilities/ConfigureButtonSets_32.png"
":/Icons/CommandPanel/Utilities/ConfigureButtonSets_20.png"
":/Icons/CommandPanel/Utilities/ConfigureButtonSets_24.png"
":/Icons/CommandPanel/Utilities/ConfigureButtonSets_16.png"

but nothing under ":/DrivenController/"


The Qt doc on using resources https://doc.qt.io/qt-5/resources.html suggests "you need to force initialization of your resources by calling Q_INIT_RESOURCE() with the base name of the .qrc file."
but calling
Q_INIT_RESOURCE(QtResource);
outside of any name space, in miscellaneous places did not make a difference.

 

0 Likes
Message 3 of 6

roman_woelker
Autodesk
Autodesk
Accepted solution

Hi Nicolas,


I don't see anything wrong in what you did.
There should be no need of doing an explicit initializing of the Qt resources, should be all done automatically once your dll gets loaded.
Please have a look at the automatically generated qrc_QtResource.cpp file, there should be two binary data blocks included representing your two icons on disk.
At the end of this file there is an initializer which hooks up your resources:

 

namespace {
struct initializer {
initializer() { QT_RCC_MANGLE_NAMESPACE(qInitResources_QtTestResource)(); }
~initializer() { QT_RCC_MANGLE_NAMESPACE(qCleanupResources_QtTestResource)(); }
} dummy;


You can try to set a breakpoint in the initializer() constructor to see if it gets actually triggered when your plugin is loaded.

 

I just quickly tried it myself using the QT VisualStudio tool, as lined out here:
https://doc.qt.io/qtvstools/qtvstools-managing-resources.html
and it worked without any problems.
Printing out the available icon sizes, showed that there was one included.

QIcon testIcon( ":/QtResourceTest/resources/dock_bottom.png" );
auto sizes = testIcon.availableSizes();
qDebug() << "Icon Sizes: " << sizes;

 
For what 3ds Max version would be your plugin?
Wondering if maybe the Qt resource compiler version could be wrong.
Is the Qt version you are compiling against, matching the 3ds Max Qt version?
I did my quick test with a 3dsMax on Qt 5.12.5 and my auto generated qrc_QtResource.cpp also shows up the proper version in the header.

/****************************************************************************
** Resource object code
**
** Created by: The Resource Compiler for Qt version 5.12.5
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

 


Roman Woelker
Software Development Engineer

Message 4 of 6

NICOLAS_LEONARD
Explorer
Explorer

Hi Roman,

 

Thanks for your suggestions.

  • it does break in the ctor of the initializer
  • when you say "I just quickly tried it myself using the QT VisualStudio tool", do you mean in a max plug-in?
  • I am using the 3ds max 2021 SDK
  • but you make me notice I am actually on Qt 5.14.1 not 5.12.5. The Qt UI works fine, but I'll install 5.12.5 and see if it makes a difference

 

Nicolas

0 Likes
Message 5 of 6

NICOLAS_LEONARD
Explorer
Explorer

OK, using QT v5.12.5 did the trick (though I did need to call Q_INIT_RESOURCE(QtResource) to access the icons)

 

 

Onward!

0 Likes
Message 6 of 6

roman_woelker
Autodesk
Autodesk

Great, I'm glad that you got it working with the change to v5.12.5. 🙂

I was placing my test code into a 3ds Max GUP plugin dll.
As said, I didn't need to call extra initialization code.
From what I understood reading this docu page here
https://wiki.qt.io/QtResources#Q_INIT_RESOURCE
Q_INIT_RESOURCE should be only necessary if your code is in a static lib. Otherwise the initializer constructor should do the trick.
Weird that it's not working out of the box on your end.


Roman Woelker
Software Development Engineer

0 Likes