Important: Please read the Qt Code of Conduct -

[SOLVED]QModelIndex and signal from TreeView

  • Hi all who read this.
    For a Wizard I created a wizardpage that contains a QTreeView and a QFileSystemModel for the selection of a file to read. This all goes pretty well, but now I want to implement a "file clicked" and enable the next button. I read that you need to overwrite the isCompete function. Done this. No problem, works, but now I need to validate the selected file before I enable the next button.
    I tried to connect the QTreeView clicked signal with the QModelIndex to a slot in the same wizardpage checkClicked(const QModelIndex Index).
    Somehow the Index I receive is invalid (debugger), but the Index.isValid gives true anyway. Reading the data from it then crashes. Very strange if you ask me. Any thoughts?? Here is my snippet of code:
    // Select File page
    OpenFilePage::OpenFilePage(QWidget parent)
    : QWizardPage(parent)
    setTitle(tr("File Selection"));
    setSubTitle(tr("Select the memory map file (

    // Insert the File open View/Model
    m_View = new QTreeView;
    m_SysModel = new QFileSystemModel;
    for (int Column_i = 1; Column_i < m_SysModel->columnCount(); Column_i++)
    QVBoxLayout *layout = new QVBoxLayout;
    m_FileName = new QLabel(this);
    registerField("FileName*", m_FileName);
    // Set the next button gray until file selected
    connect(m_View, &QTreeView::clicked,
            this, &OpenFilePage::checkClicked);



    • Function Name:
    • Return :
    • Description :
    • \brief

    void OpenFilePage::checkClicked(const QModelIndex &Index)
    QString FileName_str;

    if (Index.isValid() == true)
        QVariant Data_var =;
        FileName_str = Data_var.toString();
    // When the item returned is a file with .map in the end:
    if (FileName_str.contains(".map") == true)
        // Set the FileName field
        // Enable next button


    // And the class definition:
    class OpenFilePage : public QWizardPage
    explicit OpenFilePage(QWidget * parent = 0);
    void checkClicked(const QModelIndex &Index);

    bool isComplete(void);

    QTreeView * m_View;
    QFileSystemModel * m_SysModel;
    QLabel  * m_FileName;


  • Btw:
    @QVariant Data_var =;@
    is the line that gives the segfault. (no suprise with the index being invalid according the debugger.

  • Oke, strange,
    When setting the debugger below the function the read data is correct and it doesn't crash. So it's not the code that was faulty, but the debugger somehow.
    Greetz to all.

Log in to reply