Results 1 to 3 of 3

Thread: how can i access other form widget

  1. #1

    Default how can i access other form widget

    Hello.

    i have a main form and form2.ui

    in the main form i have the following code:

    Qt Code:
    1. void MainWindow::on_pushButton_2_clicked()
    2. {
    3. Form2 *f2 = new Form2;
    4. f2->show();
    5. }
    To copy to clipboard, switch view to plain text mode 
    so i started the form2.

    in the form2 i have a textEdit widget.
    1. How can i change the text from main form?
    2. How can i click a f2's pushButton or how can i call a function declared in form2.
    Thanks.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how can i access other form widget

    You should read about signals and slots

    And i really recommend you to stop naming the slots for the auto-connect (the on_WidgetName_SignalName() naming convention) and first learn about signals, slots and how the connection works, then you can use auto-connect if you find it useful.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can i access other form widget

    Secondly, think about encapsulation. Changing the text of a text edit widget from a different form than the owner is not recommended and isn't possible by default (the members are all private). Instead, create a method that takes a class pointer (or in this case, even just a QString, but think about the future and ease of expandability...) and then let the form use that class/QString to populate itself.

Similar Threads

  1. Access form's widget's in other class
    By p3c0 in forum Newbie
    Replies: 3
    Last Post: 12th June 2010, 14:20
  2. Replies: 5
    Last Post: 12th March 2010, 21:43
  3. Open one Form (widget)
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 7th October 2009, 13:13
  4. How can I access public variable parent Form
    By validator in forum Qt Programming
    Replies: 14
    Last Post: 18th December 2008, 21:12
  5. access the members of the Form from a loop.
    By cbarmpar in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2008, 01:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.