fruzzo
28th February 2008, 10:57
I wrote this function that add an alarm if it don't exist yet in my Qtabwidget twAlarms but I have a problem with the function child()...infact the object alm of Alarm1 or Alarm2 (both inherits from QWidget) is empty so I can't compare correctly with the alarm that I try to add (see the line: if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) ) )
Why?
Whole code of the function:
void addAlarmToList (CAlarmMessage * alarm){
bool found = false;
//Find if the alarm just exist int the list
int count = twAlarms->count();
for (int i = count-1; i >= 0; i--) {
QVBox * tab = (QVBox *) twAlarms->page(i);
if ( !strcmp(twAlarms->label(i).latin1(),"Alarm Type 1") ) {
Alarm1 * alm = (Alarm1 *) tab->child("Alarm Type 1");
if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) )
found = true;
}
else {
Alarm2 * alm = (Alarm2 *) tab->child("Alarm Type 2");
if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) )
found = true;
}
}
if (!found) {
//Add Alarm to Alarms List
QVBox * newTab = new QVBox( twAlarms, "tab" );
newTab->setMargin(5);
QFont newTab_font( newTab->font() );
newTab_font.setBold( false );
newTab->setFont( newTab_font );
if ( (alarm->getType() == AL_TC_2_2)) {
Alarm1 * alm = new Alarm1(alarm, HIL, newTab);
connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmSent()));
twAlarms->addTab( newTab, QString::fromLatin1("Alarm Type 1") );
twAlarms->showPage( newTab );
} else
if (alarm->getType()== AL_TU_2 || alarm->getType()== AL_TU_3) {
Alarm2 * alm = new Alarm2(alarm, HIL, newTab);
connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmConfirm()));
twAlarms->addTab( newTab, QString::fromLatin1("Alarm Type 2") );
twAlarms->showPage( newTab );
}
}
}
Why?
Whole code of the function:
void addAlarmToList (CAlarmMessage * alarm){
bool found = false;
//Find if the alarm just exist int the list
int count = twAlarms->count();
for (int i = count-1; i >= 0; i--) {
QVBox * tab = (QVBox *) twAlarms->page(i);
if ( !strcmp(twAlarms->label(i).latin1(),"Alarm Type 1") ) {
Alarm1 * alm = (Alarm1 *) tab->child("Alarm Type 1");
if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) )
found = true;
}
else {
Alarm2 * alm = (Alarm2 *) tab->child("Alarm Type 2");
if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) )
found = true;
}
}
if (!found) {
//Add Alarm to Alarms List
QVBox * newTab = new QVBox( twAlarms, "tab" );
newTab->setMargin(5);
QFont newTab_font( newTab->font() );
newTab_font.setBold( false );
newTab->setFont( newTab_font );
if ( (alarm->getType() == AL_TC_2_2)) {
Alarm1 * alm = new Alarm1(alarm, HIL, newTab);
connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmSent()));
twAlarms->addTab( newTab, QString::fromLatin1("Alarm Type 1") );
twAlarms->showPage( newTab );
} else
if (alarm->getType()== AL_TU_2 || alarm->getType()== AL_TU_3) {
Alarm2 * alm = new Alarm2(alarm, HIL, newTab);
connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmConfirm()));
twAlarms->addTab( newTab, QString::fromLatin1("Alarm Type 2") );
twAlarms->showPage( newTab );
}
}
}