Results 1 to 10 of 10

Thread: Some problems about using custom widget in designer!

  1. #1
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Some problems about using custom widget in designer!

    I want to add my customed widget to designer,but it doesn't work!
    It said that in the function QWidget * NeonLightPlugin::createWidget(QWidget * parent) cannot convert 'NeonLightPlugin*' to 'Widget*'.
    And it also said error: expected constructor, destructor, or type conversion before '(' token in the last line Q_EXPORT_PLUGIN2(NeonLight, NeonLightPlugin)!!!
    What is wrong with it???
    Thanks very much!

    The plugin files are here:
    neonlightplugin.h
    Qt Code:
    1. #ifndef NEONLIGHTPLUGIN_H
    2. #define NEONLIGHTPLUGIN_H
    3. #include <QObject>
    4. #include <QIcon>
    5. #include <QWidget>
    6. #include <QString>
    7. #include <QDesignerCustomWidgetInterface>
    8.  
    9. class NeonLightPlugin:public QObject, public QDesignerCustomWidgetInterface
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. NeonLightPlugin(QObject * parent = 0);
    15.  
    16. bool isContainer() const;
    17. QIcon icon() const;
    18. QString group() const;
    19. QString includeFile() const;
    20. QString name() const;
    21. QString toolTip() const;
    22. QString whatsThis() const;
    23. QWidget *createWidget(QWidget *parent);
    24. };
    25.  
    26. #endif // NEONLIGHTPLUGIN_H
    To copy to clipboard, switch view to plain text mode 

    And the neonlightplugin.cpp

    Qt Code:
    1. #include <QWidget>
    2. #include "neonlightplugin.h"
    3.  
    4. NeonLightPlugin::NeonLightPlugin(QObject *parent)
    5. {
    6. }
    7.  
    8. QString NeonLightPlugin::name() const
    9. {
    10. return "NeonLight";
    11. }
    12.  
    13. QString NeonLightPlugin::includeFile() const
    14. {
    15. return "neonlight.h";
    16. }
    17.  
    18. QString NeonLightPlugin::group() const
    19. {
    20. return tr("Special Effect");
    21. }
    22.  
    23. QIcon NeonLightPlugin::icon() const
    24. {
    25. return QIcon(":/file/resources/light.png");
    26. }
    27.  
    28. QString NeonLightPlugin::toolTip() const
    29. {
    30. return tr("A neon light widget for special effect");
    31.  
    32. }
    33.  
    34. QString NeonLightPlugin::whatsThis()const
    35. {
    36. return tr("This widget is presented by Tan Le");
    37. }
    38.  
    39. bool NeonLightPlugin::isContainer() const
    40. {
    41. return false;
    42. }
    43.  
    44. QWidget * NeonLightPlugin::createWidget(QWidget * parent)
    45. {
    46. return new NeonLightPlugin(parent);
    47. }
    48.  
    49. Q_EXPORT_PLUGIN2(NeonLight, NeonLightPlugin)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Some problems about using custom widget in designer!

    For the first error see comment:
    Qt Code:
    1. QWidget * NeonLightPlugin::createWidget(QWidget * parent)
    2. {
    3. return new NeonLightPlugin(parent); // you should return your custom widget here
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problems about using custom widget in designer!

    Yes,thanks!But how about the second one?

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Some problems about using custom widget in designer!

    Maybe a missing include? Try:
    Qt Code:
    1. #include <QtPlugin>
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some problems about using custom widget in designer!

    First argument of Q_EXPORT_PLUGIN2 should be the name of the target library you are building. The macro itself needs to be available by including <QtPlugin>.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problems about using custom widget in designer!

    Yes,now I can build the project succefully!But I still can't see my customed widget in the designer! I run mingw32-make install ,and find that two files are created in the release folder :neonlightplugin.dll and neonlightplugin.a . What should I do to see my widget in the designer?And another question is that whether should I create the plugin in a new project and then use it in another project or both create and use the custom widget in one project?I can't find the details in the book! I have been trapped by this problem for serveral days.Thanks!!!
    Last edited by furskytl; 20th September 2011 at 14:35.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some problems about using custom widget in designer!

    Do you have Designer built with MinGW?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problems about using custom widget in designer!

    Quote Originally Posted by wysota View Post
    Do you have Designer built with MinGW?
    I don't know! I use the Qt SDk 4.7.0 downloaded from the website.


    Added after 5 minutes:


    Quote Originally Posted by wysota View Post
    Do you have Designer built with MinGW?
    I just now build the example customwidgetplugin with qt.But I can't find it in the designer,either.Am I wrong?How to use the example?I think the example must be correct,so I must do something wrong creating and using the customed widget in the designer.Help me!
    Last edited by furskytl; 20th September 2011 at 14:42.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Some problems about using custom widget in designer!

    Quote Originally Posted by furskytl View Post
    I don't know! I use the Qt SDk 4.7.0 downloaded from the website.
    As far as I know it is built with MSVC. You should have a Designer built against MinGW in the Qt's bin subdirectory, It should see your plugin, provided it is copied into the proper place.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    furskytl (20th September 2011)

  11. #10
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Some problems about using custom widget in designer!

    Yes,thank you very much!!! I go to the qt\bin directory,and run the designer there,then I can see my customed widget!!!I just open the designer item in the Qt Creator before,so I can't see the customed widget!Only now am I aware of the difference between the designer in the Creator and the Qt Designer!!! Thanks very much!!!

Similar Threads

  1. Replies: 1
    Last Post: 23rd June 2011, 23:09
  2. Replies: 1
    Last Post: 6th May 2010, 10:09
  3. Replies: 1
    Last Post: 10th December 2009, 21:31
  4. QT4: Custom widget for QT Designer
    By Michiel in forum Qt Tools
    Replies: 4
    Last Post: 4th May 2006, 13:35
  5. Custom widget + Qt Designer
    By chombium in forum Qt Tools
    Replies: 1
    Last Post: 12th April 2006, 20:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.