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. send data from one tab lineedit to another tab lineedit in tab widget

send data from one tab lineedit to another tab lineedit in tab widget

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 2 Posters 5.0k 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.
  • S Offline
    S Offline
    Siddharth jain
    wrote on last edited by
    #3

    Hi,

    Thanks for the help and reply . But the thing is that I have created separate Ui form for both the tabs i.e. I have separate header files, cpp files for both tabs( like tab1.cpp and tab2.cpp). Can you help me out with this case.

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

      Hi
      So its two forms, each having a tabwidget?

      How will it work?

      The mainwindow have BOTH tab UI at the same time?

      Or do you use it as dialogs?

      First open one, then open the second?

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        So its two forms, each having a tabwidget?

        How will it work?

        The mainwindow have BOTH tab UI at the same time?

        Or do you use it as dialogs?

        First open one, then open the second?

        S Offline
        S Offline
        Siddharth jain
        wrote on last edited by
        #5

        @mrjj

        https://s18.postimg.org/idtrbfwvt/Untitled1.png
        https://s11.postimg.org/47bujwyoj/Untitled2.png

        Sir, please see the screenshots. On the above links. Actually it is a single tab widget but I have created separate classes for both

        mrjjM 1 Reply Last reply
        0
        • S Siddharth jain

          @mrjj

          https://s18.postimg.org/idtrbfwvt/Untitled1.png
          https://s11.postimg.org/47bujwyoj/Untitled2.png

          Sir, please see the screenshots. On the above links. Actually it is a single tab widget but I have created separate classes for both

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @Siddharth-jain

          Yes, I understand you have made 2 UI forms files.

          But will you use them as windows/dialogs?

          Show them one by one like a popup window?

          Or will you embed both into the mainwindow ?

          S 1 Reply Last reply
          0
          • S Offline
            S Offline
            Siddharth jain
            wrote on last edited by
            #7

            I want to embed them in main window itself

            mrjjM 1 Reply Last reply
            0
            • mrjjM mrjj

              @Siddharth-jain

              Yes, I understand you have made 2 UI forms files.

              But will you use them as windows/dialogs?

              Show them one by one like a popup window?

              Or will you embed both into the mainwindow ?

              S Offline
              S Offline
              Siddharth jain
              wrote on last edited by
              #8

              @mrjj

              Sir,
              In short I want that when I enter my Oracle id in user details tab and click on load, then my oracle Id should appear in comp off tracker tab too.

              1 Reply Last reply
              0
              • S Siddharth jain

                I want to embed them in main window itself

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #9

                @Siddharth-jain

                Ok, then its much like the sample.

                You can use the promote feature to embed the UI into main window.

                http://doc.qt.io/qt-5/designer-using-custom-widgets.html

                OR simply new and insert them your self.

                But there is one HUGE difference.

                The UI is private.
                So you cannot easy copy text in mainwindow as you cannot acces it.

                So its better to do in the class for the UI. there you create slot for button and
                save it to a variable/structure.
                You can then take from this structure in other tab.

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  Siddharth jain
                  wrote on last edited by
                  #10

                  Sir, I am not able to understand. Can please look at the code below and suggest

                  userdetails.h

                  #ifndef USER_DATA_H
                  #define USER_DATA_H
                  #include<QDebug>
                  #include<QtSql>
                  #include<QSqlDatabase>
                  #include <QWidget>

                  namespace Ui {
                  class User_data;
                  }

                  class User_data : public QWidget
                  {
                  Q_OBJECT

                  public:
                  explicit User_data(QWidget *parent = 0);
                  ~User_data();

                  private slots:
                  void on_user_submit_clicked();

                  private:
                  Ui::User_data *ui;

                  };

                  #endif // USER_DATA_H

                  USERDETAILS.CPP

                  #include "user_data.h"
                  #include "ui_user_data.h"
                  #include<QDebug>
                  #include<QFile>
                  #include<QTextStream>

                  User_data::User_data(QWidget *parent) :
                  QWidget(parent),
                  ui(new Ui::User_data)
                  {
                  ui->setupUi(this);

                  }

                  User_data::~User_data()
                  {
                  delete ui;
                  }

                  void User_data::on_user_submit_clicked()
                  {

                  QSqlDatabase mydb= QSqlDatabase ::addDatabase("QSQLITE");
                  mydb.setDatabaseName("/d/Sqlite/user.sqlite");
                   if(!mydb.open())
                  
                        qDebug() << "Failed";
                  
                  
                   else
                        qDebug() << "Connected";
                  
                  
                  QSqlQuery qry;
                  QString id;
                   id=ui->user_id->text();
                  
                   qry.prepare("Select * from user_data where Oracle_ID='"+id+"'");
                  
                   if(qry.exec())
                  {    while(qry.next())
                     {  ui->user_name->setText(qry.value(1).toString());
                        ui->user_designation->setText(qry.value(2).toString());
                        ui->user_pid->setText(qry.value(3).toString());
                        ui->user_office->setText(qry.value(4).toString());
                        ui->user_start->setText(qry.value(5).toString());
                        ui->user_end->setText(qry.value(6).toString());
                        qDebug() << "Success";
                  
                     }
                  
                  }
                  

                  }

                  comp.h

                  #ifndef COMP_OFF_H
                  #define COMP_OFF_H
                  #include<QDebug>
                  #include<QtSql>
                  #include<QSqlDatabase>
                  #include <QWidget>

                  namespace Ui {
                  class Comp_off;
                  }

                  class Comp_off : public QWidget
                  {
                  Q_OBJECT

                  public:
                  explicit Comp_off(QWidget *parent = 0);
                  ~Comp_off();

                  private slots:
                  void on_comp_submit_clicked();

                  private:
                  Ui::Comp_off *ui;

                  };

                  #endif // COMP_OFF_H

                  comp.cpp

                  #include "comp_off.h"
                  #include "ui_comp_off.h"
                  #include<QMessageBox>
                  #include<QDebug>
                  #include<QFile>
                  #include<QTextStream>

                  Comp_off::Comp_off(QWidget *parent) :
                  QWidget(parent),
                  ui(new Ui::Comp_off)
                  {
                  ui->setupUi(this);

                  }

                  Comp_off::~Comp_off()
                  {
                  delete ui;
                  }

                  void Comp_off::on_comp_submit_clicked()
                  {

                  /* QSqlDatabase mydb= QSqlDatabase ::addDatabase("QSQLITE");
                  mydb.setDatabaseName("/d/Sqlite/comp_off.sqlite");
                  if(!mydb.open())

                        qDebug() << "Failed";
                  
                  
                   else
                        qDebug() << "Connected";
                  

                  */
                  QString id,date,hours;

                    id=ui->comp_id->text();
                    date=ui->comp_date->text();
                    hours=ui->comp_hours->text();
                  
                   QSqlQuery qry;
                   qry.prepare("Insert into compoff(Oracle_ID,Date,Hours) values ('"+id+"','"+date+"','"+hours+"')");
                  
                   if(qry.exec())
                   {
                     qDebug() << "Success";
                   }
                  
                  
                   QMessageBox::information(this,tr("Submitted"),tr("Thank you! Your Response Recorded"));
                  

                  }

                  main.cpp

                  #include "mainwindow.h"
                  #include <QApplication>

                  int main(int argc, char *argv[])
                  {
                  QApplication a(argc, argv);
                  MainWindow w;
                  w.show();

                  return a.exec();
                  

                  }

                  mainwindow.cpp

                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  #include<QWidget>
                  #include<comp_off.h>
                  #include<shift_tracker.h>
                  #include<user_data.h>
                  #include<vacation_tracker.h>

                  MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);

                  auto userdata = new User_data(this);
                  ui->user_layout->addWidget(userdata);
                  
                  auto shift = new Shift_tracker(this);
                  ui->shift_layout->addWidget(shift);
                  
                  auto vacation = new Vacation_tracker(this);
                  ui->vacation_layout->addWidget(vacation);
                  
                  
                  auto comp = new Comp_off(this);
                  ui->comp_layout->addWidget(comp);
                  

                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }

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

                    it looks fine.
                    So if you save in User_data to database, then in
                    Comp_off, you can just read the data again?

                    No need to send from edit to edit.

                    Cant the tab2 (Comp_off?) just read the data it needs ?

                    S 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      it looks fine.
                      So if you save in User_data to database, then in
                      Comp_off, you can just read the data again?

                      No need to send from edit to edit.

                      Cant the tab2 (Comp_off?) just read the data it needs ?

                      S Offline
                      S Offline
                      Siddharth jain
                      wrote on last edited by
                      #12

                      @mrjj

                      Actually Sir,

                      In userdetails database, I am having user details. So when I enter my Oracle Id in userdetails tab and click on load my other fields fetches data and populates then in user details tab. Now in comp off , I want that when i click load, it takes the oracle id from oracle id field in user detail tab. As compoff is my transaction tab.

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

                        Well, the UI is private so you need to the info accessible in
                        user detail class
                        You could use a public function
                        QString getOracleID()
                        that simply returns ui->the_line_edit->text()

                        S 1 Reply Last reply
                        2
                        • S Offline
                          S Offline
                          Siddharth jain
                          wrote on last edited by
                          #14

                          Sir,
                          Can you help with providing modifications in the code. What actually is to be done. It will be really helpful

                          1 Reply Last reply
                          0
                          • mrjjM mrjj

                            Well, the UI is private so you need to the info accessible in
                            user detail class
                            You could use a public function
                            QString getOracleID()
                            that simply returns ui->the_line_edit->text()

                            S Offline
                            S Offline
                            Siddharth jain
                            wrote on last edited by Siddharth jain
                            #15

                            @mrjj

                            Hi, I tried implemeting it. But data is not passing. Please have a look at the code.

                            Userdetail.h

                            #ifndef USER_DATA_H
                            #define USER_DATA_H
                            #include<QDebug>
                            #include<QtSql>
                            #include<QSqlDatabase>
                            #include <QWidget>

                            namespace Ui {
                            class User_data;
                            }

                            class User_data : public QWidget
                            {
                            Q_OBJECT

                            public:
                            explicit User_data(QWidget *parent = 0);
                            ~User_data();
                            signals:
                            void value(QString);
                            private slots:
                            void on_user_submit_clicked();

                            private:
                            Ui::User_data *ui;
                            QString data;

                            };

                            #endif // USER_DATA_H

                            Userdetail.cpp

                            #include "user_data.h"
                            #include "ui_user_data.h"
                            #include<QDebug>
                            #include<QFile>
                            #include<QTextStream>

                            User_data::User_data(QWidget *parent) :
                            QWidget(parent),
                            ui(new Ui::User_data)
                            {
                            ui->setupUi(this);

                            }

                            User_data::~User_data()
                            {
                            delete ui;
                            }

                            void User_data::on_user_submit_clicked()
                            {

                            QSqlDatabase mydb= QSqlDatabase ::addDatabase("QSQLITE");
                            mydb.setDatabaseName("/d/Sqlite/user.sqlite");
                             if(!mydb.open())
                            
                                  qDebug() << "Failed";
                            
                            
                             else
                                  qDebug() << "Connected";
                            
                            
                            QSqlQuery qry;
                            QString id;
                             id=ui->user_id->text();
                             data= ui->user_id->text();
                             emit value(data);
                             qry.prepare("Select * from user_data where Oracle_ID='"+id+"'");
                            
                             if(qry.exec())
                            {    while(qry.next())
                               {  ui->user_name->setText(qry.value(1).toString());
                                  ui->user_designation->setText(qry.value(2).toString());
                                  ui->user_pid->setText(qry.value(3).toString());
                                  ui->user_office->setText(qry.value(4).toString());
                                  ui->user_start->setText(qry.value(5).toString());
                                  ui->user_end->setText(qry.value(6).toString());
                                  qDebug() << "Success";
                            
                               }
                            
                            }
                            

                            }

                            comp.h

                            #ifndef COMP_OFF_H
                            #define COMP_OFF_H
                            #include<QDebug>
                            #include<QtSql>
                            #include<QSqlDatabase>
                            #include <QWidget>

                            namespace Ui {
                            class Comp_off;
                            }

                            class Comp_off : public QWidget
                            {
                            Q_OBJECT

                            public:
                            explicit Comp_off(QWidget *parent = 0);
                            ~Comp_off();

                            private slots:
                            void on_comp_submit_clicked();
                            public slots:
                            void receivevalue(QString val);

                            private:
                            Ui::Comp_off *ui;

                            };

                            #endif // COMP_OFF_H

                            Comp.cpp

                            #include "comp_off.h"
                            #include "ui_comp_off.h"
                            #include<QMessageBox>
                            #include<QDebug>
                            #include<QFile>
                            #include<QTextStream>

                            Comp_off::Comp_off(QWidget *parent) :
                            QWidget(parent),
                            ui(new Ui::Comp_off)
                            {
                            ui->setupUi(this);

                            }

                            Comp_off::~Comp_off()
                            {
                            delete ui;
                            }

                            QString id;

                            void Comp_off::receivevalue(QString value)
                            {
                            id=value;
                            }

                            void Comp_off::on_comp_submit_clicked()
                            {

                            QString date,hours;
                            
                            
                             // id=ui->comp_id->text();
                              date=ui->comp_date->text();
                              hours=ui->comp_hours->text();
                            
                             QSqlQuery qry;
                             qry.prepare("Insert into compoff(Oracle_ID,Date,Hours) values ('"+id+"','"+date+"','"+hours+"')");
                            
                             if(qry.exec())
                             {
                               qDebug() << "Success";
                             }
                            
                            
                             QMessageBox::information(this,tr("Submitted"),tr("Thank you! Your Response Recorded"));
                            

                            }

                            main.h

                            #include "mainwindow.h"
                            #include <QApplication>

                            int main(int argc, char *argv[])
                            {
                            QApplication a(argc, argv);
                            MainWindow w;
                            w.show();

                            return a.exec();
                            

                            }

                            mainwindow.h

                            #include "mainwindow.h"
                            #include "ui_mainwindow.h"
                            #include<QWidget>
                            #include<comp_off.h>
                            #include<shift_tracker.h>
                            #include<user_data.h>
                            #include<vacation_tracker.h>

                            MainWindow::MainWindow(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::MainWindow)
                            {
                            ui->setupUi(this);

                            auto userdata = new User_data(this);
                            ui->user_layout->addWidget(userdata);
                            
                            auto shift = new Shift_tracker(this);
                            ui->shift_layout->addWidget(shift);
                            
                            auto vacation = new Vacation_tracker(this);
                            ui->vacation_layout->addWidget(vacation);
                            
                            
                            auto comp = new Comp_off(this);
                            ui->comp_layout->addWidget(comp);
                            
                            User_data a;
                            Comp_off b;
                               QObject::connect(&a, SIGNAL(value(QString)),
                                                &b, SLOT(receivevalue(QString)));
                            

                            }

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

                              Hi
                              Why are you making new ones ???

                              User_data a; <<< new one ! should it not be userdata ?
                              Comp_off b; <<<<< new one!! should be comp ?
                              QObject::connect(&a, SIGNAL(value(QString)),
                              &b, SLOT(receivevalue(QString)));

                              both a,b will be deleted as soon as constructor is finished ! -
                              so this look completely wrong :)

                              Use the objects you create
                              QObject::connect(userdata , SIGNAL(value(QString)), comp , SLOT(receivevalue(QString)));

                              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