0

i have a QstackedWidget and i add QHboxLayout and QVBoxLayout to it, in my vertical layout i add 3 QCheckBox, and i add this layout with two spacer for left and right side to it, then i push this new layout with two spacer for top and bottom in horizontal layout, now i want to check if this QCheckBoxes are checked or not, but i don't know how to check this. here is my code :

QVBoxLayout *center = new QVBoxLayout();
QVBoxLayout *main = new QVBoxLayout();
    QHBoxLayout *middle = new QHBoxLayout();

    QSpacerItem *topspacer = new QSpacerItem(14, 24, QSizePolicy::Fixed, QSizePolicy::Fixed);
    QSpacerItem *buttom = new QSpacerItem(4, 4, QSizePolicy::Expanding, QSizePolicy::Expanding);
    QSpacerItem *left = new QSpacerItem(4, 4, QSizePolicy::Expanding, QSizePolicy::Expanding);
    QSpacerItem *right = new QSpacerItem(4, 4, QSizePolicy::Expanding, QSizePolicy::Expanding);
    middle->addItem(left);
    middle->addLayout(center);
    middle->addItem(right);
    center->addWidget(checkBoxEvent(QString::fromStdString("Analyze events")));
    center->addWidget(checkBoxEvent(QString::fromStdString("Edit Tracks")));
    center->addWidget(checkBoxEvent(QString::fromStdString("Analyze players")));

main->addItem(topspacer);
    main->addLayout(middle);
    main->addItem(buttom);
Qwidget *m_page = new Qwidget();
    m_page->setLayout(main);
    m_stackedWidget->addWidget(m_page);

i tried this code for accessing to elements but i get segmentation fault:

 for(int i = 0; i < m_stackedWidget->widget(2)->layout()->count(); i++) 
   if(dynamic_cast<QPushButton*>( m_stackedWidget->widget(2)->layout()->itemAt(i) )->isChecked())

this items are added to m_stackedWidget[1]

mari
  • 417
  • 1
  • 6
  • 21
  • 2
    Why don't you store pointers to all check boxes and access them directly? Why do you cast to `QPushButton` instead of casting to `QCheckBox`? Why... – vahancho Apr 16 '14 at 08:02
  • i don't store this pointers because i have too many class member and i don't want to add this check box to them, i make mistake, i cast to QCheckBox but i get segmentation fault again – mari Apr 16 '14 at 08:16
  • From Qt's class reference `void QBoxLayout::addWidget ( QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0 )` - what does your `checkBoxEvent` method ? @vahancho Բարեւ – deimus Apr 16 '14 at 08:24
  • i think the easiest way is to store pointers, thanks for your help – mari Apr 16 '14 at 09:28

0 Answers0