What kind of crash exactly? Do you get a stack strace, exception message or anything like that?...makes Qt Designer crash.
What kind of crash exactly? Do you get a stack strace, exception message or anything like that?...makes Qt Designer crash.
I've just found the cause of the problem. I did not guard against recursive calls to createExtension(). I've just done so however and I no longer get crashes, although I used a static variable like so
Qt Code:
{ static bool extensionSheetIsInitialized = false; if( !extensionSheetIsInitialized ) { extensionSheetIsInitialized = true; ... } return 0; }To copy to clipboard, switch view to plain text mode
There is now the larger issue of how to proceed. How do I assign my indexes to my widget properties? So that I can control whether they are shown in the the properties editor? Ideally what I'd like to do is to display a subset of relevant properties of the widget depending on the value of a master property. For example, the master property could represent the shape of the wigdet while the remaining properties could include radius (for circles), length for squared etc, where the radius property is displayed only of the mater property is set to circle.
Yep, thats why i added the red comment to mCreateExtensionCalled, back then i stumble upon this recursion too.
The only solution i had found was to use a "index"-"property name" map. With that in mind i would suggest you
1) enumerate all properties of your widget in the constructor of the property sheet class
2) remember those properties in the "index"-"property name" map
3) override each virtual function of the property sheet and return the appropriate property values by using the "index"-"property name" map
I'm sorry that i cannot post any additional code because it's lost. But i closely remember what i was doing back then.
Thanks for your reply.
Unfortunately, I'm getting really confused. First, I have difficulty understanding the the way indexes are assigned by Qt Designer to properties. Surely custom properties have indexes even if a custom property sheet does not exist. So does a custom property sheet prevent Qt Designer from assigning a property to a custom property? And what index ranges should be assigned to custom properties? From 0 (as Santosh Reddy suggests) or from mpDefaultPropertySheetExtension.count() , as you suggest? Also custom properties display the correct names given to them when declared with Q_PROPERTY(). What then is the purpose of QDesignerPropertySheetExtension::propertyName()?
What's more confusing is that nothing I do in my custom property sheet extension appears to show up in Qt Designer, even an exit() call or QCoreApplication::exit() does nothing. Furthermore without the use of a debugger I can't be absolutely sure that qt_extension<> returns a non-NULL default property sheet and that my custom property sheet is instantiated.
Very confused.
:(
Dont be sad, being confused is a normal reaction to this stuff as almost no example code exists. I had to solve almost everything on my own by building a debug version of Qt and debugging the inner core of Qt to get this custom property stuff working. This was a hell of a nightmare as in the end only version 4.7.0 and 4.8.2 compiled successfully without showing Qt crashes later on.
As far as i remember: the Qt designer uses the custom property sheet if defined. A custom property sheet overrides the complete property list displayed in the designer. Since you are enumerating all properties in the constructor of the property sheet class, you can implement count() like so:
Qt Code:
... ::count () { return mpIndexPropertyNameMap.size(); }To copy to clipboard, switch view to plain text mode
The Qt designer will then execute a index loop from 0 to count() - 1 and call additional methods like propertyName(), isVisible() and so on to display the properties accordingly in the property editor.
This is what i was referring to in the first comment of this post. After hours of trying to solve this via trail and error with exit() or writing log text files i compiled Qt as debug build. But you don't really have to go that hellish route, just try to write out a log file first. This should be a quite easy task.
Thanks.
I'm going to try logging for a start. Its really strange that exit() doesn't work yet leaving out the boolean variable/guard causes the application to call the QExtensionFactory::createExtension() recursively.
In the interim I've setting a property as DESIGNABLE with a boolean member function as a value instead of true or false. But this causes the property to be grayed out and not hidden.
BTW, what do you think of this recommendation? Trouble is that I'm not quite sure which class does this? QDesignerCustomWidgetInterface perhaps?
This has something to do with the internals of Qt, you could see why it doesn't work when using a debug version of Qt. I cannot remember what it was exactly but i had the same problem too, then i changed to logging via text files.
Hehe, i had the same issue too. As far as i remember the designable thing is a bit buggy, just skip it if you don't really need it. If you need a read only property in the property editor then use QDesignerPropertySheetExtension::isVisible(), there's a reason why it exists
Yes, this is the way to make properties a bit more dynamic. You should keep in mind that the Qt designer buffers many values returned by QDesignerPropertySheetExtension (i cannot recall which ones exactly), it's done when Qt designer starts. I used this approach to dynamically hide / show properties by using a context menu.
Depends on what you want to achieve. As i stated above, for me it was the click handler of the context menu that executed this code. Just place it where you need it as it's based on a static function.
Logging to a text file is surprisingly instructive. 'Shows that for some strange strange reason QExtensionFactory::createExtension() is called for QCheckBox only!???
@Olumide
Hmm strange. You should upload your complete source code somewhere so i can have a look at it.
That was bug/typo. Its now working properly, although I had to create the property extension on the parent extension and not on the widget itself, as shown below:
Qt Code:
QDesignerPropertySheetExtension* defaultPropertySheetExtension = qt_extension<QDesignerPropertySheetExtension*>( m_extensionManager , parent );To copy to clipboard, switch view to plain text mode
Bookmarks