Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. StackedLayout : segmentation fault at slot :: nextSlide1()
Forum Updated to NodeBB v4.3 + New Features

StackedLayout : segmentation fault at slot :: nextSlide1()

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 562 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #1

    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);

    }

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      @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);

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved