Results 1 to 2 of 2

Thread: Find a Tab

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Find a Tab

    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:
    Qt Code:
    1. void addAlarmToList (CAlarmMessage * alarm){
    2. bool found = false;
    3.  
    4. //Find if the alarm just exist int the list
    5. int count = twAlarms->count();
    6. for (int i = count-1; i >= 0; i--) {
    7. QVBox * tab = (QVBox *) twAlarms->page(i);
    8. if ( !strcmp(twAlarms->label(i).latin1(),"Alarm Type 1") ) {
    9. Alarm1 * alm = (Alarm1 *) tab->child("Alarm Type 1");
    10. if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) )
    11. found = true;
    12. }
    13. else {
    14. Alarm2 * alm = (Alarm2 *) tab->child("Alarm Type 2");
    15. if ( (alarm->getTrackId() == alm->getTrackId()) && (alarm->getType()==alm->getType()) )
    16. found = true;
    17. }
    18. }
    19.  
    20. if (!found) {
    21. //Add Alarm to Alarms List
    22. QVBox * newTab = new QVBox( twAlarms, "tab" );
    23. newTab->setMargin(5);
    24. QFont newTab_font( newTab->font() );
    25. newTab_font.setBold( false );
    26. newTab->setFont( newTab_font );
    27.  
    28. if ( (alarm->getType() == AL_TC_2_2)) {
    29. Alarm1 * alm = new Alarm1(alarm, HIL, newTab);
    30. connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmSent()));
    31. twAlarms->addTab( newTab, QString::fromLatin1("Alarm Type 1") );
    32. twAlarms->showPage( newTab );
    33.  
    34. } else
    35. if (alarm->getType()== AL_TU_2 || alarm->getType()== AL_TU_3) {
    36. Alarm2 * alm = new Alarm2(alarm, HIL, newTab);
    37. connect(alm, SIGNAL(buttonClicked()), this, SLOT(alarmConfirm()));
    38. twAlarms->addTab( newTab, QString::fromLatin1("Alarm Type 2") );
    39. twAlarms->showPage( newTab );
    40. }
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by fruzzo; 28th February 2008 at 10:05.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Find a Tab

    you are not breaking out of the for loop when you find the Alarm you are looking for.
    So the loop goes all the way until the last 'i', and if the last 'i' is not Alarm2, then you get "not found".

Similar Threads

  1. GCC can't find QSqlDatabase!!
    By brevleq in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2007, 07:05
  2. Cannot find file: winmain.pro in Qt installation
    By jivanr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th June 2007, 12:22
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  4. QT string Find problem
    By kingslee in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 20:45
  5. Replies: 7
    Last Post: 1st August 2006, 21:15

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.