Results 1 to 5 of 5

Thread: Qt Designer closes when trying to add a custom widget into a form

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Qt Designer closes when trying to add a custom widget into a form

    Hi,

    This mornig I tried to add a custom widget of mine into a dialog form and each time it makes qt designer close. I don't know why.

    My widget is quite simple and is composed of 5 bitmaps.

    Here is the code of the .h of my widget
    Qt Code:
    1. #ifndef _HMI_ITEM_SOUND_TESTER_H
    2. #define _HMI_ITEM_SOUND_TESTER_H
    3.  
    4. #include <qwidget.h>
    5.  
    6. class CHmiItemSound;
    7. class QLabel;
    8.  
    9. class CHmiItemSoundTester : public QWidget
    10. {
    11. // Constructor / Desctuctor
    12. public:
    13. CHmiItemSoundTester(QWidget* parent=0, const char* name=0);
    14.  
    15. // Functions
    16. void updateItem(const CHmiItemSound&);
    17. void showItem();
    18. void hideItem();
    19. void testItem();
    20.  
    21. // Members
    22. private:
    23. CHmiItemSound* itemSound;
    24.  
    25. QLabel* car;
    26. QLabel* hpAvGa;
    27. QLabel* hpAvDr;
    28. QLabel* hpArGa;
    29. QLabel* hpArDr;
    30. };
    31.  
    32. #endif
    To copy to clipboard, switch view to plain text mode 

    ... the .cpp
    Qt Code:
    1. #include "HmiItemSoundTester.h"
    2. #include <qlabel.h>
    3. #include <qpixmap.h>
    4. #include ".\\..\\..\\HmiItemSound\\WidgetSource\\HmiItemSound.h"
    5. #include <qsound.h>
    6.  
    7. CHmiItemSoundTester::CHmiItemSoundTester(QWidget* parent, const char* name):
    8. {
    9. // Construct the CHmiItemSound
    10. itemSound = new CHmiItemSound();
    11.  
    12. // Construct the representation of a sound item
    13. resize(228, 396);
    14. // ... the background bitmap
    15. voiture = new QLabel(this, "voiture");
    16. voiture->setGeometry(0, 0, 228, 396);
    17. voiture->setPixmap( QPixmap("1007.png") );
    18. //voiture->hide();
    19.  
    20. // ... the the hp bitmaps
    21. hpAvGa = new QLabel(this, "hpAvGa");
    22. hpAvGa->setGeometry(30, 93, 69, 93);
    23. hpAvGa->setPixmap( QPixmap("speaker_left.png") );
    24. //hpAvGa->hide();
    25.  
    26. hpAvDr = new QLabel(this, "hpAvDr");
    27. hpAvDr->setGeometry(125, 93, 69, 93);
    28. hpAvDr->setPixmap( QPixmap("speaker_right.png") );
    29. //hpAvDr->hide();
    30.  
    31. hpArGa = new QLabel(this, "hpArGa");
    32. hpArGa->setGeometry(30, 221, 69, 93);
    33. hpArGa->setPixmap( QPixmap("speaker_left.png") );
    34. //hpArGa->hide();
    35.  
    36. hpArDr = new QLabel(this, "hpArDr");
    37. hpArDr->setGeometry(125, 221, 69, 93);
    38. hpArDr->setPixmap( QPixmap("speaker_right.png") );
    39. //hpArDr->hide();
    40. }
    41.  
    42.  
    43. void CHmiItemSoundTester::updateItem(const CHmiItemSound& value)
    44. {
    45. itemSound->setSoundFileName( value.getSoundFileName() );
    46. itemSound->setSoundDuration( value.getSoundDuration() );
    47. itemSound->setSoundLevel( value.getSoundLevel() );
    48. itemSound->setSoundPlayMode( value.getSoundPlayMode() );
    49. itemSound->setSoundRestitutionModeHpFrontLeft( value.getSoundRestitutionModeHpFrontLeft() );
    50. itemSound->setSoundRestitutionModeHpFrontRight( value.getSoundRestitutionModeHpFrontRight() );
    51. itemSound->setSoundRestitutionModeHpRearLeft( value.getSoundRestitutionModeHpRearLeft() );
    52. itemSound->setSoundRestitutionModeHpRearRight( value.getSoundRestitutionModeHpRearRight() );
    53. }
    54.  
    55.  
    56. void CHmiItemSoundTester::showItem()
    57. {
    58. voiture->show();
    59.  
    60. if( itemSound->getSoundRestitutionModeHpFrontLeft() )
    61. hpAvGa->show();
    62. else
    63. hpAvGa->hide();
    64.  
    65. if( itemSound->getSoundRestitutionModeHpFrontRight() )
    66. hpAvDr->show();
    67. else
    68. hpAvDr->hide();
    69.  
    70. if( itemSound->getSoundRestitutionModeHpRearLeft() )
    71. hpArGa->show();
    72. else
    73. hpArGa->hide();
    74.  
    75. if( itemSound->getSoundRestitutionModeHpRearRight() )
    76. hpArDr->show();
    77. else
    78. hpArDr->hide();
    79.  
    80. }
    81.  
    82.  
    83. void CHmiItemSoundTester::hideItem()
    84. {
    85. voiture->hide();
    86. hpAvGa->hide();
    87. hpAvDr->hide();
    88. hpArGa->hide();
    89. hpArDr->hide();
    90. }
    91.  
    92.  
    93. void CHmiItemSoundTester::testItem()
    94. {
    95. QSound sound(itemSound->getSoundFileName());
    96.  
    97. sound.play();
    98. }
    To copy to clipboard, switch view to plain text mode 

    The .h code of my plugin
    Qt Code:
    1. #include <qwidgetplugin.h>
    2. #include <qwidget.h>
    3.  
    4. class QT_WIDGET_PLUGIN_EXPORT CHmiItemSoundTesterPlugin : public QWidgetPlugin
    5. {
    6. public:
    7. CHmiItemSoundTesterPlugin();
    8.  
    9. QStringList keys() const;
    10. QWidget* create(const QString& classname, QWidget* parent=0, const char* name=0);
    11. QString group(const QString&) const;
    12. QIconSet iconSet(const QString&) const;
    13. QString includeFile(const QString&) const;
    14. QString toolTip(const QString&) const;
    15. QString whatsThis(const QString&) const;
    16. bool isContainer(const QString&) const;
    17. };
    To copy to clipboard, switch view to plain text mode 

    ... the .cpp
    Qt Code:
    1. #include "HmiItemSoundTesterPlugin.h"
    2. #include ".\\..\\WidgetSource\\HmiItemSoundTester.h"
    3.  
    4. CHmiItemSoundTesterPlugin::CHmiItemSoundTesterPlugin()
    5. :QWidgetPlugin()
    6. {
    7.  
    8. }
    9.  
    10. QStringList CHmiItemSoundTesterPlugin::keys() const
    11. {
    12. list << "CHmiItemSoundTesterPlugin";
    13. return list;
    14. }
    15.  
    16. QWidget* CHmiItemSoundTesterPlugin::create(const QString& key, QWidget* parent, const char* name)
    17. {
    18. if( key == "CHmiItemSoundTesterPlugin" )
    19. return new CHmiItemSoundTester(parent, name);
    20. return 0;
    21. }
    22.  
    23. QString CHmiItemSoundTesterPlugin::includeFile(const QString& feature) const
    24. {
    25. if( feature == "CHmiItemSoundTesterPlugin" )
    26. return "HmiItemSoundTester.h";
    27. return QString::null;
    28. }
    29.  
    30. QString CHmiItemSoundTesterPlugin::group(const QString& feature) const
    31. {
    32. if( feature == "CHmiItemSoundTesterPlugin" )
    33. return "MyWidgets";
    34. return QString::null;
    35. }
    36.  
    37. QIconSet CHmiItemSoundTesterPlugin::iconSet(const QString& feature) const
    38. {
    39. return QIconSet( QPixmap("hmiitemsoundtester_pixmap.png"));
    40. }
    41.  
    42. QString CHmiItemSoundTesterPlugin::toolTip(const QString& feature) const
    43. {
    44. if( feature == "CHmiItemSoundTesterPlugin" )
    45. return "Sound Tester Widget";
    46. return QString::null;
    47. }
    48.  
    49. QString CHmiItemSoundTesterPlugin::whatsThis(const QString& feature) const
    50. {
    51. if( feature == "CHmiItemSoundTesterPlugin" )
    52. return "A widget to test a sound";
    53. return QString::null;
    54. }
    55.  
    56. bool CHmiItemSoundTesterPlugin::isContainer(const QString& feature) const
    57. {
    58. return FALSE;
    59. }
    60.  
    61. Q_EXPORT_PLUGIN( CHmiItemSoundTesterPlugin );
    To copy to clipboard, switch view to plain text mode 

    ... then the .pro file of my widget
    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
    3. ######################################################################
    4.  
    5. SOURCES += HmiItemSoundTesterPlugin.cpp ../WidgetSource/HmiItemSoundTester.cpp ../../HmiItem/WidgetSource/HmiItem.cpp ../../HmiItemSound/WidgetSource/HmiItemSound.cpp
    6. HEADERS += HmiItemSoundTesterPlugin.h ../WidgetSource/HmiItemSoundTester.h ../../HmiItem/WidgetSource/HmiItem.h ../../HmiItemSound/WidgetSource/HmiItemSound.h
    7. DESTDIR = $(QTDIR)/plugins/designer
    8. TARGET = hmiitemsoundtesterplugin
    9.  
    10. target.path = $$plugins.path
    11. isEmpty(target.path):target.path==$$QT_PREFIX/plugins
    12. INSTALLS += target
    13. TEMPLATE = lib
    14. CONFIG += qt warn_on release plugin
    15. INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
    16. DBFILE = plugin.db
    17. PROJECTNAME = Plugin
    18. LANGUAGE = C++
    To copy to clipboard, switch view to plain text mode 

    If someone knows what's wrong or had the same problem.

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default [SOLVED] Re: Qt Designer closes when trying to add a custom widget into a form

    ... I got it !

    I did not pass parent widget and widget name parameters to the base class of CHmiItemSoundtester (QWidget)

    So that is why the compilation was ok but the insertion of my widget failed.

    [SOLVED]

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Qt Designer closes when trying to add a custom widget into a form

    hmm ... in fact I still have a problem with my widget. When I had it to a form, it appears to be a QWidget object and not a CHmiItemSoundTester object.

    Why ?

  4. #4
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Qt Designer closes when trying to add a custom widget into a form

    about the last problem I mentionned, I replaced some functions by same slots, I compile it and then when I insert my widget into a form it appears to be a CHmiItemSoundTester and not a base class object.

    Finally I have a last question. As my widget uses some bitmaps which are external to it, where do I must store them to make my widget be able to display them ?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Designer closes when trying to add a custom widget into a form

    Quote Originally Posted by yellowmat
    it appears to be a QWidget object and not a CHmiItemSoundTester object.

    Why ?
    Because you forgot to add Q_OBJECT macro:
    Qt Code:
    1. class CHmiItemSoundTester : public QWidget
    2. {
    3. Q_OBJECT
    4. // Constructor / Desctuctor
    5. public:
    6. CHmiItemSoundTester(QWidget* parent=0, const char* name=0);
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by yellowmat
    where do I must store them to make my widget be able to display them ?
    You could place them in an image collection. Check qmake docs (look for IMAGES variable).

Similar Threads

  1. Custom widget - Only works in Designer
    By Darhuuk in forum Qt Tools
    Replies: 6
    Last Post: 8th January 2008, 01:46
  2. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 16:38
  3. QT4: Custom widget for QT Designer
    By Michiel in forum Qt Tools
    Replies: 4
    Last Post: 4th May 2006, 14:35
  4. Custom widget + Qt Designer
    By chombium in forum Qt Tools
    Replies: 1
    Last Post: 12th April 2006, 21:33
  5. Replies: 4
    Last Post: 2nd March 2006, 00:11

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.