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 to get info from one form to another

How to get info from one form to another

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 389 Views 1 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.
  • DriftwoodD Offline
    DriftwoodD Offline
    Driftwood
    wrote on last edited by
    #1

    C++ provides a lot of obstacles for a noob, namely this noob. The latest brick wall I hit is my trying to use the value held in a MainWindow lineEdit on a Dialog form. I've tried this:

    ui->label_6->setText( MainWindow::ui->lineEdit_MyInt->text() );
    

    But since ui is a MainWindow private member, I get an error. I have to access the MainWindow lineEdit_MyInt (holds the cust_id of a customer selected in a tablewidget) so that I can write the the entered Dialog info to the correct customer. And, of course, I don't have to use label_6; that's just a visual aid as I try to sort this out.

    How can I access MainWindow's lineEdit_MyInt on the Dialog form?

    jsulmJ 1 Reply Last reply
    0
    • DriftwoodD Driftwood

      C++ provides a lot of obstacles for a noob, namely this noob. The latest brick wall I hit is my trying to use the value held in a MainWindow lineEdit on a Dialog form. I've tried this:

      ui->label_6->setText( MainWindow::ui->lineEdit_MyInt->text() );
      

      But since ui is a MainWindow private member, I get an error. I have to access the MainWindow lineEdit_MyInt (holds the cust_id of a customer selected in a tablewidget) so that I can write the the entered Dialog info to the correct customer. And, of course, I don't have to use label_6; that's just a visual aid as I try to sort this out.

      How can I access MainWindow's lineEdit_MyInt on the Dialog form?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Driftwood I guess you instantiate and call the dialog in your main window?
      In that case it is as simple as pass all needed data to the dialogs constructor:

      class MyDialog : public QDialog
      {
      public:
          MyDialog(const QString text, ...) {...}
      }
      
      // In MainWindow:
      MyDialog myDialog(ui->lineEdit_MyInt->text());
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        For sparsely used dialogs passing the data in the constructor as @jsulm mentioned, is adequate. For dialogs that are frequently displayed it is arguably more optimal to create the dialog early and use the signal slot mechanism to feed data to its fields, then exec() it when it is to be realized.

        setText() is a slot, albeit private in the conext of the ui...so subclass the dialog, making a public setText() slot for the fields you need to send data to, then connect that slot to the signals that will feed it data.

        As a noob, you must well learn the signal/slot mechanism to use QT effectively.

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        1 Reply Last reply
        2

        • Login

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