Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[RESOLVED] use UI element in functions



  • How can I use UI elements in my functions ?
    For example:

    @void MainWindow::MyFunc (QTableview MyTable)
    {
    ui->MyTable->setenabled(true);
    }

    /////////////////////////////////////////////////////////////////

    void MainWindow::on_pushButton_clicked()
    {
    MyFunc(ui->table1);
    }
    @

    Thank you, and sory for my english.



  • You did it almost right.
    Here is fixed version.
    @
    // You pass a pointer to the function
    void MainWindow::MyFunc (QTableView* MyTable)
    {
    // Here you use that pointer.
    MyTable->setEnabled(true);
    }

    /////////////////////////////////////////////////////////////////
    void MainWindow::on_pushButton_clicked()
    {
    // I assume that ui->table1 is QTableView*
    MyFunc(ui->table1);
    }
    @



  • Oh a pointer, of corse !

    Yes table1 is QTableview*
    Now it's working :)

    THANK YOU WERY MUCH !


Log in to reply