aboutsummaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorConfuSomu2023-01-21 19:35:32 -0500
committerConfuSomu2023-01-21 19:35:32 -0500
commita17d022463fc0e0a28c888cedf018c3c964ef110 (patch)
tree301b1ce329a15e0fa9d944a7027b36f8ef4e1408 /src/mainwindow.cpp
parent8a8659a8f94575a1ce6bdd732f9b4af0237cae42 (diff)
downloadActorViewer-a17d022463fc0e0a28c888cedf018c3c964ef110.tar
ActorViewer-a17d022463fc0e0a28c888cedf018c3c964ef110.tar.gz
ActorViewer-a17d022463fc0e0a28c888cedf018c3c964ef110.zip
Fix out of range errors in on_buttonSearch_clicked
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b33889a..28af716 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -8,6 +8,7 @@
#include <QRandomGenerator>
#include <QClipboard>
#include <QMimeData>
+#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -103,13 +104,15 @@ void MainWindow::on_buttonSearch_clicked() {
QString current_search = ui->textInputSearch->text();
+ QList<QListWidgetItem*> matches = ui->listWidget->findItems(current_search, Qt::MatchContains);
+
if (not (*last_search == current_search)) {
*last_search = current_search;
selected_match = 0;
- } else
- ++selected_match;
+ } else if (++selected_match >= matches.size()) selected_match = 0;
+
+ qDebug() << matches.size() << selected_match;
- QList<QListWidgetItem*> matches = ui->listWidget->findItems(current_search, Qt::MatchContains);
if (not matches.isEmpty()) {
ui->listWidget->scrollToItem(matches[selected_match], QAbstractItemView::EnsureVisible);
ui->listWidget->setCurrentItem(matches[selected_match]);