Qt World Summit: Register Today!

Class name mismatch when creating custom widget from QtDesigner

  • I am coding a plugin for the Designer to add some widgets I have created. Before adding the code, I created the project through File -> New Project -> Other Project -> Qt Custom Designer Widget.

    If I add a custom widget that inherits straight from QWidget, i.e. QWidget -> MyWidget, it shows nicely in the Designer. But most of my widgets does not inherit directly from QWidget. Instead, they inherit from a custom base class that implements some shared functionality, e.g. QWidget -> MyScale -> MyCompass.

    When this happens, although MyCompass is shown correctly by the Designer, a dialog appears with the message: "Designer: A class name mismatch occurred when creating a widget using the custom widget factory registered for widgets of class MyCompass. It returned a widget of class MyScale.

    If I check the UI file generated by the Designer, it really registers the widget as MyScale, instead of MyCompass.

    How can I fix this?

  • I encountered the same error and found the solution in this other post. I was missing the Q_OBJECT macro in the class that I was creating the plugin for.

  • Lifetime Qt Champion

    @apalomer Do you really think it's worth answering to a thread which is already 6 years old?

  • Yes, I do think so. This post was what I was finding as the first suggested link all the time regardless of how I formulated my question to google. I assumed many others may encounter this helpful, hence, I decided to post an answer. Moreover, the error has not changed through the years (the post where I found the answer is from August 2008), therefore, I find the question still valid and needed an answer.

  • @apalomer Tankes for your anwser. you are a good man

Log in to reply