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
Code:
#ifndef _HMI_ITEM_SOUND_TESTER_H
#define _HMI_ITEM_SOUND_TESTER_H
#include <qwidget.h>
class CHmiItemSound;
class CHmiItemSoundTester
: public QWidget{
// Constructor / Desctuctor
public:
CHmiItemSoundTester
(QWidget* parent
=0,
const char* name
=0);
// Functions
void updateItem(const CHmiItemSound&);
void showItem();
void hideItem();
void testItem();
// Members
private:
CHmiItemSound* itemSound;
};
#endif
... the .cpp
Code:
#include "HmiItemSoundTester.h"
#include <qlabel.h>
#include <qpixmap.h>
#include ".\\..\\..\\HmiItemSound\\WidgetSource\\HmiItemSound.h"
#include <qsound.h>
CHmiItemSoundTester
::CHmiItemSoundTester(QWidget* parent,
const char* name
):{
// Construct the CHmiItemSound
itemSound = new CHmiItemSound();
// Construct the representation of a sound item
resize(228, 396);
// ... the background bitmap
voiture
= new QLabel(this,
"voiture");
voiture->setGeometry(0, 0, 228, 396);
voiture
->setPixmap
( QPixmap("1007.png") );
//voiture->hide();
// ... the the hp bitmaps
hpAvGa
= new QLabel(this,
"hpAvGa");
hpAvGa->setGeometry(30, 93, 69, 93);
hpAvGa
->setPixmap
( QPixmap("speaker_left.png") );
//hpAvGa->hide();
hpAvDr
= new QLabel(this,
"hpAvDr");
hpAvDr->setGeometry(125, 93, 69, 93);
hpAvDr
->setPixmap
( QPixmap("speaker_right.png") );
//hpAvDr->hide();
hpArGa
= new QLabel(this,
"hpArGa");
hpArGa->setGeometry(30, 221, 69, 93);
hpArGa
->setPixmap
( QPixmap("speaker_left.png") );
//hpArGa->hide();
hpArDr
= new QLabel(this,
"hpArDr");
hpArDr->setGeometry(125, 221, 69, 93);
hpArDr
->setPixmap
( QPixmap("speaker_right.png") );
//hpArDr->hide();
}
void CHmiItemSoundTester::updateItem(const CHmiItemSound& value)
{
itemSound->setSoundFileName( value.getSoundFileName() );
itemSound->setSoundDuration( value.getSoundDuration() );
itemSound->setSoundLevel( value.getSoundLevel() );
itemSound->setSoundPlayMode( value.getSoundPlayMode() );
itemSound->setSoundRestitutionModeHpFrontLeft( value.getSoundRestitutionModeHpFrontLeft() );
itemSound->setSoundRestitutionModeHpFrontRight( value.getSoundRestitutionModeHpFrontRight() );
itemSound->setSoundRestitutionModeHpRearLeft( value.getSoundRestitutionModeHpRearLeft() );
itemSound->setSoundRestitutionModeHpRearRight( value.getSoundRestitutionModeHpRearRight() );
}
void CHmiItemSoundTester::showItem()
{
voiture->show();
if( itemSound->getSoundRestitutionModeHpFrontLeft() )
hpAvGa->show();
else
hpAvGa->hide();
if( itemSound->getSoundRestitutionModeHpFrontRight() )
hpAvDr->show();
else
hpAvDr->hide();
if( itemSound->getSoundRestitutionModeHpRearLeft() )
hpArGa->show();
else
hpArGa->hide();
if( itemSound->getSoundRestitutionModeHpRearRight() )
hpArDr->show();
else
hpArDr->hide();
}
void CHmiItemSoundTester::hideItem()
{
voiture->hide();
hpAvGa->hide();
hpAvDr->hide();
hpArGa->hide();
hpArDr->hide();
}
void CHmiItemSoundTester::testItem()
{
QSound sound
(itemSound
->getSoundFileName
());
sound.play();
}
The .h code of my plugin
Code:
#include <qwidgetplugin.h>
#include <qwidget.h>
class QT_WIDGET_PLUGIN_EXPORT CHmiItemSoundTesterPlugin : public QWidgetPlugin
{
public:
CHmiItemSoundTesterPlugin();
QWidget* create
(const QString
& classname,
QWidget* parent
=0,
const char* name
=0);
QString group
(const QString
&) const;
QIconSet iconSet(const QString&) const;
QString includeFile
(const QString
&) const;
QString toolTip
(const QString
&) const;
QString whatsThis
(const QString
&) const;
bool isContainer(const QString&) const;
};
... the .cpp
Code:
#include "HmiItemSoundTesterPlugin.h"
#include ".\\..\\WidgetSource\\HmiItemSoundTester.h"
CHmiItemSoundTesterPlugin::CHmiItemSoundTesterPlugin()
:QWidgetPlugin()
{
}
{
list << "CHmiItemSoundTesterPlugin";
return list;
}
QWidget* CHmiItemSoundTesterPlugin
::create(const QString
& key,
QWidget* parent,
const char* name
) {
if( key == "CHmiItemSoundTesterPlugin" )
return new CHmiItemSoundTester(parent, name);
return 0;
}
QString CHmiItemSoundTesterPlugin
::includeFile(const QString
& feature
) const {
if( feature == "CHmiItemSoundTesterPlugin" )
return "HmiItemSoundTester.h";
}
QString CHmiItemSoundTesterPlugin
::group(const QString
& feature
) const {
if( feature == "CHmiItemSoundTesterPlugin" )
return "MyWidgets";
}
QIconSet CHmiItemSoundTesterPlugin::iconSet(const QString& feature) const
{
return QIconSet
( QPixmap("hmiitemsoundtester_pixmap.png"));
}
QString CHmiItemSoundTesterPlugin
::toolTip(const QString
& feature
) const {
if( feature == "CHmiItemSoundTesterPlugin" )
return "Sound Tester Widget";
}
QString CHmiItemSoundTesterPlugin
::whatsThis(const QString
& feature
) const {
if( feature == "CHmiItemSoundTesterPlugin" )
return "A widget to test a sound";
}
bool CHmiItemSoundTesterPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CHmiItemSoundTesterPlugin );
... then the .pro file of my widget
Code:
######################################################################
# Automatically generated by qmake (1.07a) dim. 29. janv. 10:37:16 2006
######################################################################
SOURCES += HmiItemSoundTesterPlugin.cpp ../WidgetSource/HmiItemSoundTester.cpp ../../HmiItem/WidgetSource/HmiItem.cpp ../../HmiItemSound/WidgetSource/HmiItemSound.cpp
HEADERS += HmiItemSoundTesterPlugin.h ../WidgetSource/HmiItemSoundTester.h ../../HmiItem/WidgetSource/HmiItem.h ../../HmiItemSound/WidgetSource/HmiItemSound.h
DESTDIR = $(QTDIR)/plugins/designer
TARGET = hmiitemsoundtesterplugin
target.path = $$plugins.path
isEmpty(target.path):target.path==$$QT_PREFIX/plugins
INSTALLS += target
TEMPLATE = lib
CONFIG += qt warn_on release plugin
INCLUDEPATH += $(QTDIR)/tools/designer/interfaces
DBFILE = plugin.db
PROJECTNAME = Plugin
LANGUAGE = C++
If someone knows what's wrong or had the same problem.
Thanks in advance
[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]
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 ?
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 ?
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:
Code:
class CHmiItemSoundTester
: public QWidget{
Q_OBJECT
// Constructor / Desctuctor
public:
CHmiItemSoundTester
(QWidget* parent
=0,
const char* name
=0);
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).