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 the ui filed from one cpp file to another cpp file?
Forum Updated to NodeBB v4.3 + New Features

How to get the ui filed from one cpp file to another cpp file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.1k 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.
  • N Offline
    N Offline
    nani1169
    wrote on last edited by
    #1

    How to get the ui filed values ,from one cpp file to another cpp file?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Normally the first UI would store the data to some data structure and
      the second UI would just read from there. Like database system.

      You have to give more details on how you mean / what you are trying.
      as input of a say a name
      could be made as one operation. ( pop dialog, and return name to mainwind for use)
      but other types of input need to be saved and access later.

      If you have a live floating dialog, (like a tool window for imaging program), one can easy use signal and slots to
      send data.

      1 Reply Last reply
      1
      • N Offline
        N Offline
        nani1169
        wrote on last edited by
        #3

        i design one editfield (take for example username) in sqlDesigner.ui and i can able to get that field value in sqlDesigner.cpp by using (ui->username).
        but i want that field value in mainWindow.cpp file?
        so how could i get that value ?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Well you can just add a new public function.

          QString sqlDesigner::GetUserName() {
          return ui->username->text();
          }

          and then just call that from main on your sqlDesigner instance to get the string.

          Its not a good idea to let other classes have direct access to the inner UI as it leads
          to a program that is hard to change and a very messy structure.

          1 Reply Last reply
          3
          • N Offline
            N Offline
            nani1169
            wrote on last edited by
            #5
            MainWindow* MainWindow::mw;
            MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent), ui(new Ui::MainWindow)
            ,mDbConnection(ip,"SQL Server",username,passwd,Dbname,true)
            {
                ui->setupUi(this);
            }
            i have above code in mainWindow.cpp
            ip,username,passwd,Dbname are the parameters ,i have these parameter values in SqlDesigner.cpp and
            i want these parameter values to mainWindow.cpp
            but problem is first mainWindow.cpp is run and it take the null values.after that parameter values are passed form sqlDesigner.
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              You could change main.cpp to first show SqlDesigner and then when closed
              get the paramters from it and give it to mainwindow where its constructed.

              
              int main(int argc, char* argv[]) {
                QApplication a(argc, argv);
                SqlDesigner sdd;
                sdd.exec(); // assumes its dialog. 
                // get the parameters here ? Maybe use a struct.
                MainWindow w(0,ip,"SQL Server",username,passwd,Dbname);
                w.show();
                return a.exec();
              }
              
              1 Reply Last reply
              3

              • Login

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