Results 1 to 4 of 4

Thread: Program crashes if i want to clear() a combobox!?

  1. #1
    Join Date
    Jan 2012
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Program crashes if i want to clear() a combobox!?

    Hi there
    i dont know how to solve one problem.
    I designed a controlpanel for my program with QtDesigner and added controlpanel.cpp and controlpanel.h to be able to add more functionality.
    Now i have a problem:
    On the GUI there are several Comboboxes. If a new ControlPanel is created all comboboxes should be cleared and initialized with some items.

    Controlpanel.h
    Qt Code:
    1. #ifndef CONTROLPANEL_H
    2. #define CONTROLPANEL_H
    3. #include <QMainWindow>
    4. #include "ui_controlpanel.h"
    5.  
    6. class ControlPanel : public QMainWindow, public Ui::ControlPanel
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. ControlPanel();
    12.  
    13. private:
    14. void initStatusVectors();
    15. void setComboBoxes();
    16.  
    17. QVector<QString> statusVec;
    18. };
    19.  
    20.  
    21. #endif // CONTROLPANEL_H
    To copy to clipboard, switch view to plain text mode 

    And this is Controlpanel.cpp
    Qt Code:
    1. #include <QMainWindow>
    2. #include <QtGui>
    3. #include "controlpanel.h"
    4.  
    5. //INITIALIZE STATUS-VECTOR
    6. void ControlPanel::initStatusVectors()
    7. {
    8. statusVec.push_back("1");
    9. statusVec.push_back("2");
    10. statusVec.push_back("3");
    11. statusVec.push_back("4");
    12. statusVec.push_back("5");
    13. statusVec.push_back("6");
    14. statusVec.push_back("7");
    15. statusVec.push_back("8");
    16. statusVec.push_back("9");
    17. }
    18.  
    19. void ControlPanel::setComboBoxes()
    20. {
    21. this->combStatus1->clear();
    22. }
    23.  
    24. ControlPanel::ControlPanel(QWidget *parent)
    25. : QMainWindow(parent)
    26. {
    27. //INITIALIZE STATUS-VECTOR
    28. initStatusVectors();
    29.  
    30. setComboBoxes();
    31.  
    32. setupUi(this);
    33. }
    To copy to clipboard, switch view to plain text mode 

    If i leave out setComboBoxes() everything works fine i guess. Nothing bad happens.
    But if i call setComboBoxes(); the program crashes before showing the GUI. So i press CTRL+R and then the crash message of windows appears
    "ControlPanel has crashed and so on..."

    I really dont know whats the problem is? Can anyone help me?

    Greetz

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    18
    Thanked 68 Times in 66 Posts

    Default Re: Program crashes if i want to clear() a combobox!?

    your program crashes because "combStatus1" is NULL. you have to call "setupUi(this)" to initialize your ui.

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Program crashes if i want to clear() a combobox!?

    Where do you initialize this->combStatus1 ?
    edit: you have to initialize ui first, then use it, not the other way around

  4. #4
    Join Date
    Jan 2012
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: Program crashes if i want to clear() a combobox!?

    Oh ok thanks Yes it makes sense to initialize the ui first^^

Similar Threads

  1. Program crashes on OS X Lion
    By fyodor in forum Newbie
    Replies: 1
    Last Post: 31st October 2011, 06:18
  2. Program crashes
    By Fallen_ in forum Qt Programming
    Replies: 49
    Last Post: 20th September 2010, 01:41
  3. program a combobox in a dialog
    By Devoraz in forum Newbie
    Replies: 3
    Last Post: 29th July 2009, 10:42
  4. program crashes (QtTestRunner)
    By fmariusd in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 09:27
  5. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09

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.