PDA

View Full Version : Promote Qwidget problem, class already exists ???



tonnot
8th February 2011, 13:09
I have a Qwidget component. It is named MyWidget
It works ok.
If I define the promoted widget to 'mywidget' , QTCreator let me.
But when I want to build I see errors related with there is no 'mywidget reference'.
I have to change manually to 'MyWidget' (with M and W uppercase letters) and all works fine.
If I want to define the promoted widget with 'MyWidget' letters, QTCreator says me 'The class already exists' ....
I have reset QtCreator, but nothing changes....
What I'm doing bad ?


P.D. And ..... What means 'Global include' when you define the promoted W.? (I dont see nothing at help docs)

Thanks

high_flyer
8th February 2011, 13:10
Do you understand what promoting a widget is?
Can you explain what it is?

tonnot
8th February 2011, 13:22
Yes I have read the help. And see :

In all other cases, where the source code to the custom widgets is available, we can adapt the custom widget for use with Qt Designer.
But ... I dont want to spent time building the plugin.
And.... I remember (when begin to learn QT) that I could to use 'promote' to use custom widgets....

Can you help me ?

high_flyer
8th February 2011, 13:48
You didn't answer my question:
What does promoting a widget do?
I ask, to be sure you understand what it is.

tonnot
8th February 2011, 13:55
As you said a time ago :

Promoting a widget is nothing more than telling designer that it should trust you, and in the UI file, it will create the class you promoted to, and put the include file for your custom file in the ui.
So when the ui compiler makes C++ code out of your ui, in your project where your custom class is known, it will compile and when you run the application, your gui will show your custom widget where the promoted widget is on the from.
Ergo - in designer, at design time, designer knows nothing about your promoted widget, and it will only show the base widget it knows.
If you want to have your custom widget "designable" in designer, you will have to create a designer plugin out of your custom widget.
But, I cant do this ....
I have see other posts.... 'Simply write the name of the class and the header ....' This is just what I do .... but QTCreator-Designer says me 'class already exists' ....

high_flyer
8th February 2011, 14:18
Lol.
So you posted my answer - good to know I know what promotion is. :)
But ok, lets go one step further:

But, I cant do this ....
Now if you only explain what 'this' means, we might be able to help you - what it is you are trying to achieve?
Please note:
I ask about the end result you are after, not the way you are trying to do it!

tonnot
8th February 2011, 14:28
Promote can let me to use custom widgets without building the plugin ?
This is the main idea I have about it, I'm wrong ?

high_flyer
8th February 2011, 14:37
Promote can let me to use custom widgets without building the plugin ?
This is the main idea I have about it, I'm wrong ?
now you have answered my questions from before.
Good.
It depends how you mean what you said, to judge if you are wrong or not.
Promoting allows you to use a custom widget in designer, which IS implemented in your code, but not as a designer plugin.
Now by "use in designer" I mean, you can have a base widget of your custom widgets serve as a place holder in the form for your custom widget.
You then "promote" the base widget to your own custom widget, so that creator will generate the right headers, and class names when it generates the ui.
But you wont see your custom widget in designer just because you promoted a widget!
You can only have instances of widgets that are supplied to designer via the designer plugins system.
That is all!
It will not save you from actually implementing your custom widget!

tonnot
8th February 2011, 16:41
Thanks for your patience H.F.
But.... You say :

You then "promote" the base widget to your own custom widget, so that creator will generate the right headers, and class names when it generates the ui.
But I can't write the correct name of my class.... (because QT says me that 'it's already exists...)
Ok, then I see the ui_form.h code and see 'mywidget' instance. I change it to 'MyWidget' (I have MyWidget.h and MyWidget.cpp), and I build my project. Ok ! It works. But, if I re-open the .ui form, QT rewrites my ui_form.h again bad...
I dont want to see MyWidget in designer (I know that I have to build the plugin) But I want to test it .
If I have the h and cpp files for MyWidget.... What more must i do ?
Thanks again-

high_flyer
8th February 2011, 18:30
I have hard time understanding what it is you are doing, but you are clearly doing something you shouldn't.

Ok, then I see the ui_form.h code and see 'mywidget' instance. I change it to 'MyWidget' (I have MyWidget.h and MyWidget.cpp), and I build my project.
Do you mean you are changing the ui_form.h?
If this is what you are doing you should not do it, since the uic will overwrite it each time it builds the ui file.
If you promote your widget correctly, it will appear correctly in the ui_form.h with out the need to modify it.

squidge
8th February 2011, 22:51
I have a Qwidget component. It is named MyWidget
It works ok.
What do you mean, it is named MyWidget?

If I define the promoted widget to 'mywidget' , QTCreator let me. But when I want to build I see errors related with there is no 'mywidget reference'.
Which is correct, you have to write the code yourself... The promotion is only for designer and uic...

I have to change manually to 'MyWidget' (with M and W uppercase letters) and all works fine.
Don't understand this. What are you changing? I thought MyWidget was name of QWidget, not class name.

wysota
8th February 2011, 23:10
I think the OP wants to say that the promotion dialog let's him enter "mywidget" as the name of the class to promote QWidget to but doesn't let him enter "MyWidget". It's hard to say exactly why this happens without knowing what were the exact steps undertaken to reach the situation. It might be that there already is a "MyWidget" promotion defined or that such a class name is known to Designer because a plugin for such a class exists. Or there is a variable called "MyWidget" which might also prevent Designer from allowing such promotion. This is all just a guess, the OP really needs to work on his communication skills :)

ChrisW67
8th February 2011, 23:34
If I define the promoted widget to 'mywidget' , QTCreator let me.
But when I want to build I see errors related with there is no 'mywidget reference'.

You told Qt Creator (Designer) that there was a QWidget derived class called "mywidget" defined in mywidget.h (or something it includes) and there wasn't. It is hardly surprising that code generated on that basis doesn't compile. Designer cannot reasonably check this in advance without including substantial portions of C pre-processor and compiler functionality and being able to determine what options the real compiler, which may not be the compiler you are using on your machine, will eventually be run with.


I have to change manually to 'MyWidget' (with M and W uppercase letters) and all works fine.

This is what you should have told Qt Creator from the start.


If I want to define the promoted widget with 'MyWidget' letters, QTCreator says me 'The class already exists' ....

I cannot reproduce this. Demote the widget, remove the incorrect promotion entry, create a correct promotion entry, and promote the widget, problem solved.

tonnot
9th February 2011, 08:32
Thanks for your patience. (and excuse my comunication skills, probably also because my poor english)
I know that I have not to change the ui.h file (simply I saw the error when build using a 'mywidget' class -Not in uppercase-, and tried to write the uppercase name of the class )

'MyWidget' were a 'literal' way to name the widget. Really it is the 'WallClock' from Analogwidgets (QTapps org, Tomasz Ziobrowski)
Ok, I have copied and renamed wallclock to ww (h and cpp) and the class name 'WallClock' to 'Ww'.

I dont know what it happens but 'Ww' works !. Qt let me to define a promoted entry named Ww (but not WallClock) and when build I see the clock.
I leave the zip file with the files (I dont know what is the problem but cannot attach a .rar file....)
Can you test it ?
Thanks

wysota
9th February 2011, 08:51
My guess would be there is a widget plugin for the WallClock widget available. From what I see in the source archive for AnalogWidgets that's exactly the case.

tonnot
9th February 2011, 09:11
Yes ..... Excuse for this horrible post.
Maybe if the message had been 'There is a plugin with this class already defined'
Thanks wysota.

wysota
9th February 2011, 11:40
If there is a plugin defined why do you want to promote widgets?

tonnot
9th February 2011, 14:37
The plugin has 5 widgets and I wanted to test one of them (with some changes).
Simply I didn't remember that the pluging was loaded, there were a widget with the same name class that the one I wanted it to be promoted.

Thanks

wysota
9th February 2011, 14:54
I suggest that in future when some software or a person tells you some message why a particular thing doesn't work, try to search for the problem stated by the message before assuming some conspiracy of the software or person against you.