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
#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
#ifndef _HMI_ITEM_SOUND_TESTER_H
#define _HMI_ITEM_SOUND_TESTER_H
#include <qwidget.h>
class CHmiItemSound;
class QLabel;
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;
QLabel* car;
QLabel* hpAvGa;
QLabel* hpAvDr;
QLabel* hpArGa;
QLabel* hpArDr;
};
#endif
To copy to clipboard, switch view to plain text mode
... the .cpp
#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();
}
#include "HmiItemSoundTester.h"
#include <qlabel.h>
#include <qpixmap.h>
#include ".\\..\\..\\HmiItemSound\\WidgetSource\\HmiItemSound.h"
#include <qsound.h>
CHmiItemSoundTester::CHmiItemSoundTester(QWidget* parent, const char* name):
QWidget()
{
// 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();
}
To copy to clipboard, switch view to plain text mode
The .h code of my plugin
#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;
};
#include <qwidgetplugin.h>
#include <qwidget.h>
class QT_WIDGET_PLUGIN_EXPORT CHmiItemSoundTesterPlugin : public QWidgetPlugin
{
public:
CHmiItemSoundTesterPlugin();
QStringList keys() const;
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;
};
To copy to clipboard, switch view to plain text mode
... the .cpp
#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 );
#include "HmiItemSoundTesterPlugin.h"
#include ".\\..\\WidgetSource\\HmiItemSoundTester.h"
CHmiItemSoundTesterPlugin::CHmiItemSoundTesterPlugin()
:QWidgetPlugin()
{
}
QStringList CHmiItemSoundTesterPlugin::keys() const
{
QStringList list;
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";
return QString::null;
}
QString CHmiItemSoundTesterPlugin::group(const QString& feature) const
{
if( feature == "CHmiItemSoundTesterPlugin" )
return "MyWidgets";
return QString::null;
}
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";
return QString::null;
}
QString CHmiItemSoundTesterPlugin::whatsThis(const QString& feature) const
{
if( feature == "CHmiItemSoundTesterPlugin" )
return "A widget to test a sound";
return QString::null;
}
bool CHmiItemSoundTesterPlugin::isContainer(const QString& feature) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( CHmiItemSoundTesterPlugin );
To copy to clipboard, switch view to plain text mode
... then the .pro file of my widget
######################################################################
# 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++
######################################################################
# 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++
To copy to clipboard, switch view to plain text mode
If someone knows what's wrong or had the same problem.
Thanks in advance
Bookmarks