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. QCompleter & QTreeview get crash on MacOS and Qt 5.12.2

QCompleter & QTreeview get crash on MacOS and Qt 5.12.2

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 451 Views
  • 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.
  • G Offline
    G Offline
    Gulivert
    wrote on last edited by Gulivert
    #1

    Greetings to all,

    For a QLineEdit I tried to create an auto-completer from a list requested on an API server. I'm able to have the correct behavior but some time when the dialog window is opening the whole application crash. If I remove the whole code to create the QCompleter I do not have this crash.
    It seems I did something not correctly but as I'm new with Qt I cannot figure out what is wrong and why sometime the dialog works as expected and sometime the app just crash.

    Here is how I create and bind my QCompleter to QLineEdit, maybe you will see something wrong...

    void CreateAppointmentDialog::patientsFetched(QJsonArray patients)
    {
        // Create an auto completer
        QCompleter *completer = new QCompleter(this);
        completer->setCompletionMode(QCompleter::PopupCompletion);
        completer->setCaseSensitivity(Qt::CaseInsensitive);
        completer->setMaxVisibleItems(10); // No effect ?
        completer->setFilterMode(Qt::MatchContains);
    
    
        // Create a new model to list patients
        QStandardItemModel *patientsModel = new QStandardItemModel(patients.count(), 3, completer);
    
        int counter = 0;
        foreach (const QJsonValue &value, patients) {
            QJsonObject patientObj = value.toObject();
    
            QModelIndex patientNameIdx = patientsModel->index(counter, 0);
            QModelIndex patientBirthdateIdx = patientsModel->index(counter, 1);
            QModelIndex patientIdIdx = patientsModel->index(counter, 2);
            QString patientName = patientObj["lastname"].toString() + " " +  patientObj["firstname"].toString();
            QString patientBirthdate = patientObj["birthdate"].toString() != "" ? QDate::fromString(patientObj["birthdate"].toString(), Qt::ISODate).toString("dd.MM.yyyy") : "";
            QString patientId = patientObj["id"].toString();
            patientsModel->setData(patientNameIdx, patientName);
            patientsModel->setData(patientBirthdateIdx, patientBirthdate);
            patientsModel->setData(patientIdIdx, patientId);
    
            counter++;
        }
    
        completer->setModel(patientsModel);
    
        QTreeView *treeView = new QTreeView;
        completer->setPopup(treeView);
        treeView->setRootIsDecorated(false);
        treeView->hideColumn(2);
        treeView->header()->hide();
        treeView->header()->setStretchLastSection(false);
        treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
        treeView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
    
        ui->patientsEdit->setCompleter(completer);
    
        connect(treeView, &QTreeView::clicked, [=]{
            selectedPatientId = treeView->currentIndex().sibling(treeView->currentIndex().row(),2).data().toString();
        });
    }
    

    Any help will be really appreciate.

    Regards,

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gulivert
      wrote on last edited by
      #2

      After investigating it seems that QCompleter is not my problem.
      Then I think I need to learn how to debug my app to understand from where this crash is coming.

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        The first start is just to start the app in debug mode (f5) and get it to crash.
        That will show a list of called methods until it crashed.
        That often gives a good clue to what is happening.

        alt text

        1 Reply Last reply
        2
        • G Offline
          G Offline
          Gulivert
          wrote on last edited by
          #4

          Thank's for your advise!
          I finally figured out what was wrong and the problem was coming from the customContextMenu where I specified a bad table to popup the menu from QModelIndex in the parent where I called the dialog CreateAppointmentDialog.

          Sorry I was sure that it was first coming from the combo of QCompleter & QTreeview.

          1 Reply Last reply
          2

          • Login

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