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. How do I code for different widget passed ?
Forum Updated to NodeBB v4.3 + New Features

How do I code for different widget passed ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 280 Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1
    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      You need to make a cast of the variable:

      QTexEdit* edit=qobject_cast<QTextEdit*>(widget);
      if(edit)
      {
      edit->append(text);
      }
      
      A 1 Reply Last reply
      2
      • M mpergand

        You need to make a cast of the variable:

        QTexEdit* edit=qobject_cast<QTextEdit*>(widget);
        if(edit)
        {
        edit->append(text);
        }
        
        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @mpergand Thanks works great.

        1 Reply Last reply
        0

        • Login

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