To test QScroller on my Android device,
I have written a simple HelloWorld-like application with QStackedWidget with 2 pages.
Every page has a single QListWidget with a number of items.
On startup, the app shows page_2 of the stacked widget with a number of items. QScroller is attached programmatically to this QListWidget:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(1);
scroller = QScroller::scroller(ui->listWidget_2);
scroller->grabGesture(ui->listWidget_2);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(1);
scroller = QScroller::scroller(ui->listWidget_2);
scroller->grabGesture(ui->listWidget_2);
}
To copy to clipboard, switch view to plain text mode
On application startup everything is ok. QScroller attached is working fine with the QListWidget.
After that I press "Go to page 1" button which removes the entire page from the stacked widget and attach QScroller to the second QListWidget :
void MainWindow::on_pushButton_clicked()
{
QScroller::ungrabGesture(ui->listWidget_2);
ui->stackedWidget->removeWidget(ui->page_2);
ui->page_2->deleteLater();
ui->page_2 = nullptr;
QScroller* scroller2 = QScroller::scroller(ui->listWidget);
scroller2->grabGesture(ui->listWidget);
}
void MainWindow::on_pushButton_clicked()
{
QScroller::ungrabGesture(ui->listWidget_2);
ui->stackedWidget->removeWidget(ui->page_2);
ui->page_2->deleteLater();
ui->page_2 = nullptr;
QScroller* scroller2 = QScroller::scroller(ui->listWidget);
scroller2->grabGesture(ui->listWidget);
}
To copy to clipboard, switch view to plain text mode
The widget is displayed OK. But when I try to scroll it with my fingers, the app crashes with SIGSEGV(Segmentation fault) and the stack is:
#10 qtMainLoopThread
1. QWidget* object_cast<QWidget*>(QObject*)
2. QFlickGestureRecognizer::recognize(QGesture*, QObject*, QEvent*)
3. ???
What am i doing wrong???
The complete source code of the application is attached
Bookmarks