StackedLayout : segmentation fault at slot :: nextSlide1()



  • Debugging, show segmentation fault at slot nextSlide1()
    No problem using comboBox to page QStackedLayout but when i switch to timer, the slot nextSlide show segmentation fault.

    '''
    Widget::Widget(QWidget *parent) : QWidget(parent)
    {

    QLabel *firstPageWidget = new QLabel("one");
    QLabel *secondPageWidget = new QLabel("two");
    
    QStackedLayout *stackedLayout = new QStackedLayout;
    stackedLayout->addWidget(firstPageWidget);
    stackedLayout->addWidget(secondPageWidget);
    
     //    QComboBox *pageComboBox = new QComboBox;
      //    pageComboBox->addItem(tr("Page 1"));
      //    pageComboBox->addItem(tr("Page 2"));
    

    // connect(pageComboBox, SIGNAL(activated(int)),
    // stackedLayout, SLOT(setCurrentIndex(int)));

       timershift = new QTimer(this);
       connect(timershift,SIGNAL(timeout()),this, SLOT(nextSlide1()));
       timershift->start(1200); 
    
       QVBoxLayout *mainLayout = new QVBoxLayout;
       mainLayout->addLayout(stackedLayout);
       setLayout(mainLayout);
    

    }
    void Widget::nextSlide1()
    {
    stackedLayout->setCurrentIndex(stackedLayout->currentIndex()+1);

    }



  • @houmingc said:

    try to replace:
    stackedLayout->setCurrentIndex(stackedLayout->currentIndex()+1);

    with
    if( stackedLayout->currentIndex() < stackedLayout->count() - 1)
    stackedLayout->setCurrentIndex(stackedLayout->currentIndex()+1);
    else
    stackedLayout->setCurrentIndex(0);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.