Important: Please read the Qt Code of Conduct -

How do I code for different widget passed ?

  • How do I code (C++) for different widget passed  to a function ? 
    I am trying to learn how to pass variable wiglets  to a function and 
    code the function for variable widgets. 
     Here is my function 
    int  Form::UpdateForm(QWidget *widget, QString text)  ) 
    And this is how I use it: 
    UpdateForm((QTextEdit*)ui->textEdit, "TEST TRACE ");
    In this case I pass  QTextEdit but I cannot use methods for 
    QTextEdit. I can only use generic QWidget methods. 
    widget.append(text)  does not compile - no such method for "widget" .

    I ask Mrs Google but she only does when the function is declared with specific type of widget. I need a variable type of widget to process.

    Any (C++ code) help would be appreciated.

  • You need to make a cast of the variable:

    QTexEdit* edit=qobject_cast<QTextEdit*>(widget);

  • @mpergand Thanks works great.

Log in to reply