Important: Please read the Qt Code of Conduct -

Cannot access private member?

  • I have this trigger function for a Window i created:

    void MainWindow::on_searchProdutos_textChanged()
    QSqlQuery* qry = new QSqlQuery(DATABASE_NAME);
    QSqlQueryModel* modal = new QSqlQueryModel;

    qry->prepare("select * from clientes");


    And the compiler gives me the following error...
    64: error: C2248: 'QListWidget::setModel': cannot access private member declared in class 'QListWidget'

    I've already coded several functions like these already, why is it erroring out here?

    Thanks in advance for any help! =)

  • It looks like your listProdutos is a QListWidget instead of a QListView. If you want to work with the model/view concept you want to use just the plain QListView. The QListWidget is a convenience widget that merges a QListView and a corresponding model into one widget. The model in that widget is a private attribute and thus you get the error that you are not allowed to access that member.

  • It now doesn't cause any error anymore. I checked the attributes at Qt's qt 5.6 page, but was checking indeed for QListView, instead of QListWidget so wasn't figuring out what the issue was.
    Thank you for that! =)

Log in to reply