Results 1 to 6 of 6

Thread: Problem in activating a combobox at run time.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Problem in activating a combobox at run time.

    Hi all
    I am activating combobox at run time in following slot
    Qt Code:
    1. list_combobox.clear();
    2. for(int i=0; i<obj_schedule_table->rowCount(); i++)
    3. {
    4. QWidget *widget1;
    5. widget1 = obj_schedule_table->cellWidget(i,3);
    6. QComboBox *combo = (QComboBox*)widget1->children().at(1);
    7. combo->setEditable(false);
    8. list_combobox<<combo;
    9. }
    10. signalMapper_selection = new QSignalMapper(this);
    11. for(int i=0; i<list_combobox.size(); i++)
    12. {
    13. signalMapper_selection->setMapping(list_combobox.at(i), i);
    14. connect(list_combobox.at(i), SIGNAL(activated(QString)), signalMapper_selection, SLOT (map()));
    15. connect(signalMapper_selection, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
    16. }
    To copy to clipboard, switch view to plain text mode 

    this slot is called on clicking a button "edit"

    in remove_row slot i again connect these combobox to appropriate slots

    Qt Code:
    1. signalMapper_selection = new QSignalMapper(this);
    2. QLineEdit *line_edit = (QLineEdit *)obj_schedule_table->cellWidget(index,0);
    3. disconnect(list_combobox.at(index),0,0,0);
    4. obj_schedule_table->removeRow(index);
    5. list_combobox.removeAt(index);
    6. for(int i=0; i<obj_schedule_table->rowCount(); i++)
    7. {
    8. signalMapper_selection->setMapping(list_combobox.at(i), i);
    9. connect(list_combobox.at(i), SIGNAL(activated(QString)), signalMapper_selection, SLOT (map()));
    10. connect(signalMapper_selection, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
    11. }
    To copy to clipboard, switch view to plain text mode 

    When i remove a row and than activate a combobox in row below than that row it give segmantaion fault while working fine above the removed row.

    Please help me what i am doing wrong.

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Problem in activating a combobox at run time.

    you probably use the row that you just erased.

    or it may be a deal of multithreading if you have.

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Problem in activating a combobox at run time.

    how i have to solve this problrm can you give some code example

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem in activating a combobox at run time.

    Your code is very error prone (like static casting to QComboBox). Maybe try simplifying it first to make sure something else doesn't affect it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Problem in activating a combobox at run time.

    When i remove a row and than activate a combobox in row below than that row it give segmantaion fault while working fine above the removed row
    It is difficult to understand what is going on there, but a common mistake is to use the same row index as it was before deletion, but keep in mind when you delete an item everything below it will have indexes decreased by one.

  6. #6
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Problem in activating a combobox at run time.

    hi again,

    Can you debug the code and tell us the line number where does the error excatly occur?

Similar Threads

  1. MDI subWindow activating when switching toolbox page
    By zenzero-2001 in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2011, 18:46
  2. Activating Console in VS2008 Qt Integration Gui App
    By sepp in forum Qt Programming
    Replies: 6
    Last Post: 5th December 2010, 13:51
  3. Precent QDialog from de-activating mainwindow
    By Arthur in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2010, 12:01
  4. selecting/activating tabify'd DockWidget?
    By iraytrace in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2010, 18:44
  5. Activating multiple windows
    By lixo1 in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2009, 20:54

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
  •  
Qt is a trademark of The Qt Company.