Problem with resource files in VS2005
-
I started to use Qt and my goal is to apply it to an already existing application (so starting a new project from a wizard is not an option)
I did the following, using the visual Studio addon:
-
added a new Qt form to the project, and edited it in Qt Designer
-
compiled it and added the header created by the custom build step of the above .ui file to the project
-
created a MainWindow.h and MainWindow.cpp as in the samples. Now I can use the mainWindow.show();app.exec(); form my code and the window is displayed, so I assume Qt is up and running.
-
added the custom build step for the MOC to the header file, a moc_MainWindow.cpp is generated, I add it to the project
-
I would like to add an icon to one of my buttons. I add a new .qrc file (Add/New Items../Qt Resources/Qt Resource) to the project, and add a .png image to it in the Qt Resource Editor. I add a custom bild step to the .qrc file (I copied it from the qrc file in tha project which is created when I use the wizard to create a new Qt Application project), so a qrc_Icons.cpp is generated which I add to the project.
-
When I run the program, the icons don't appear at all. I'm sure the compiler can find them, because: 1. if I rename or remove the image file, the compilation stops with an error that it can't find it, 2. The qrc_Icons.cpp is "filled up with data" when the image is added with the Qt Resource Editor:
@static const unsigned char qt_resource_data[] = {
// .... .png
0x0,0x0,0x8,0x19,
0x89,
0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0, // ... and so on for a couple of hundered of lines.@- In the Qt Designer, I use the action editor to set this image as an icon to a toolbar item. The icon appears correctly in the Qt Designer, but if I build and run my program, just an empty square appears instead of it.
What did I miss? If I create an application from scratch with the wizard, the icons work perfectly.
And, by the way, which is the best strategy to use the gui with my application? It already has a command-line interface, I just wanted to add a gui, where I can push buttons and call my already implemented functions, and I would like to keep the gui as much segregated as possible from the rest of my code. Should I just call functions from the MainWindow.cpp and keep track of eventual setting variables with a static class? Or is there some fancy Qt feature which does this better?
-