PDA

View Full Version : CustomWidget plugin in Qt5.4 not working



sueyllam
30th April 2015, 20:34
I have downloaded the Qt5.4 binaries for mingw and realizing that QtCreator is built using Visual studio, I downloaded the QtCreator sources and built it using the Qt5.4 mingw, so now I have a Qt Creator built using mingw. I tried the analog clock custom widget plugin example included with Qt5.4 examples, I built it and copied both the dll and lib.a into both folders for QtCreator built with mingw and the Qt5.4 plugins.
The analog clock appears in the left hand side along with the standard widgets and I am able to drag it into the main form, The project build fine, but When I try to run it, I get the following error:

QWidget: Must construct a QApplication before a QWidget
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.

Any idea what possibly have I done wrong?

d_stranz
30th April 2015, 20:54
realizing that QtCreator is built using Visual studio

It is totally, completely, absolutely irrelevant what language, compiler, or anything else that Qt Creator is built with. It could have been written in Martian and built using Martian Studio. Qt Creator is just another program. It is self-contained, and provides any Qt or other DLLs libraries it uses independently of the compiler you use. So you wasted your time rebuilding it.

What matters is the kit that Qt Creator uses to build your project. In this case, if you installed a minGW Qt, and use minGW to build your projects, then you must ensure that the DLLs in the path are minGW-built DLLs, and that you are linking a release build with release DLLs only, and debug build with debug DLLs only.

The error you are seeing is usually the result of incorrect DLL loading (i.e. wrong path) or more often a mixup of release and debug binaries. Check to make sure that if your plugin was built in release mode, you are loading it into a release mode exe. You cannot mix-and-match debug and release anywhere.

sueyllam
1st May 2015, 04:04
Well thanks for the expert reply. I changed the build settings in QtCreator to release and it is running fine.
However, for the benefit of other newbies, rebuilding qtcreator using qt5.4-mingw from sources was not waste of time. Everything is working fine under the new rebuilt qtcreator. However when I use the originally supplied qtcreator (built using Visual studio), after of course copying the dll and lib.a to the proper folders, the custom widgets do not even appear in qtcreator along with the standard widgets so it does not work. I read about this in stack-overflow about people having the same problem and it was explained that mingw and visual studio use different name mangling so they are not compatible...

d_stranz
1st May 2015, 17:05
I read about this in stack-overflow about people having the same problem and it was explained that mingw and visual studio use different name mangling so they are not compatible...

Yes, MSVC and minGW (as well as any other C++ compiler) will each have a different version of name mangling.

The point you are missing is that you do not use the DLLs from Qt Creator's installation directory when building and linking your own Qt app. You use the DLLs from your Qt installation. Yes, you can build Qt Creator from source if you want to, but it has no relevance to using it to build your own Qt projects.

If you are getting link or run-time errors, it is because your environment path or Qt kit configuration are loading and/or linking to the wrong DLLs. I use vanilla, straight out of the box Qt Creator to build Qt apps on Windows using Visual Studio 2008, Visual Studio 2013 and minGW 4.9.1, and I cross-compile for Android and linux using the same Qt Creator and cross-compilers. What you have to ensure is that when you configure the Qt Creator "kit" for whatever you are targeting, it is using the correct compiler, linker, make-specs and header files, and precompiled libraries / DLLS for that kit. The best way to ensure that is to either download a pre-built Qt distribution or build it from sources using the compiler and make-specs file for the target environment.

I have independent Qt distributions for all of the compilers / targets I mentioned above, installed side-by-side on my development disk. I have only one copy of Qt Creator, and I use it for all of them.

sueyllam
1st May 2015, 19:12
As much as what you say makes sense I cannot figure out what is wrong with my QtCreator built using MSVC, Here are snapshots showing its default kit and the fact that both custom widgets are not showing:
1115011149

Now for the QtCreator I built, it uses the same kit and both custom widgets are shown, the analog clock and the iconeditor:
1115111152

And I followed the same procedure by adding the dll and lib.a of both custom widgets to the proper folders of both Qt and The corresponding QtCreator.
Could it be possibly has to do that the packaged QtCreator is on the C: drive with the Qt5.4, while the one I built is on the D: drive, where I built the custom widgets?

Added after 23 minutes:

Well clearly it does not make a difference where the custom widget libraries are built; just tried to build them on C:. Same disappointment...Cannot figure out any other reason!

sueyllam
1st May 2015, 21:42
Well after doing some search on the net, I found the following pdf document which explicitly states that you have to build qtcreator from the sources in order to be able to use plugins: Here is a snapshot...
11154

So I guess I had to build qtcreator anyway in order to add and create plugins. May be your point was that I did not have to use mingw I could have done it using MS Visual Studio and It would have run as well for plugins created with mingw Qt? was that your point?

d_stranz
1st May 2015, 22:08
So I guess I had to build qtcreator anyway in order to add and create plugins.

Oh, it's my misunderstanding - I thought you were creating a plugin to use in your application. Yes, if you want to add a custom plugin to Qt Creator, the plugin does have to be built with the same compiler and version of Qt that your copy of Qt Creator uses. If you don't have that compiler, then yes, a rebuild of Qt Creator and the plugin with the same compiler and Qt version is required.

Sorry, my mistake.

ChrisW67
1st May 2015, 22:14
There are two different types of plugin:

Plugins you write to be used in your program at run time must be built with the same tool chain as your program and the Qt libraries it uses. This need not be related to the tool chain used to build Qt Creator.
Plugins used to make a custom widget accessible and usable in Qt Designer's tool box (standalone or embedded in Qt Creator). These plugins must be built with the same tool chain as the Qt Designer/Qt Creator And installed into the relevant location for those tools to locate and load.