Promoting widgets in Qt Creator

Qt creator has option to promote one widget to customly created class that derives from base widget - I want to use that to promote widget to class in current project. Qt creator asks me about class name and header filename, and those value go directly to *.ui file, and then to ui_myform.h - the problem is that this file might be (and usually is) generated outside source tree (in build tree) which can be at arbitrary location, so direct specification of path in promoting window will not help. How to let QtCreator/uic know where to look for right header? Is it even possible?

Perhaps there is some Qt variable specyfying location of source tree, that I could insert in header filename field?

I am using self-compiled QtCreator 2.0.1 + self-compiled Qt 4.7.1.

EDIT:

Why can't you just type in the complete path name of the header file?

What if I will move source tree, or even share it on the web - then everybody who wants to compile my project would have to edit this path either in Qt creator or in source files - both are unacceptable.

Answers


The header file that Designer asks you for in the promotion dialog is YOUR own header file that define the custom widget, not the generated ui_*.h file.

Say you want to promote a plain QWidget to MyCustomWidget, you must already have a MyCustomWidget.h that defines your MyCustomWidget class included in your .pro file like this:

HEADERS  += MyCustomWidget.h

And in the widget promotion dialog, just type in MyCustomWidget.h. The purpose of it is so the generated ui header file (wherever it is) can include YOUR class definition.


I already figured this thing out - I was promoting to my class, and giving header name that was self-written, that was correct.

The problem was that this (self written) file was not directly in the project directory but in src subdirectory (where all others sources also are), I am not using subdirs template, but simply adding them like

SOURCES += src/myWidget.cpp

The promoting option doesn't require full path, but it needs it as it appears in *.pro file - in this case switching from myWidget.h to src/myWidget.h did the trick - and it will work if I move or share it.


If the promoted widget form (.ui) and class files (.cpp, .h) are in a Qt Creator project subdirectory and j_kubik's solution does not help it shows the error ("foo.h not found"), try to use just the header file name for the promotion and provide the path as INCLUDEPATH in the .pro file.


Need Your Help

Setting text to fit the size of a UILabel and centre in SWIFT

swift uiview uilabel

I'm trying to set text to fit the size of a UILabel and also be centred. I am doing this programmatically. This is what it looks like currently:

How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?

java android browser

So I want to create an Android app so it would be registered somewhere in android OS (or just would start on system start) and when phone user clicks on special button on a web page inside a web br...