Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to retriew data from one ui to other ui in the same project.
Qt 6.12 LTS is out! See what's new in the release blog

How to retriew data from one ui to other ui in the same project.

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 3 Posters 3.1k 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.
  • M Offline
    M Offline
    moyin
    wrote on last edited by
    #1

    Actually i hav mainwindow.ui and view.ui two ui's in my project.
    now i want read data from one of the qtablewidget data of mainwindow.ui from view.cpp
    so how can i reffer to mainwidow.ui object in view.cpp.
    please help.

    1 Reply Last reply
    0
    • yuvaramY Offline
      yuvaramY Offline
      yuvaram
      wrote on last edited by
      #2

      Hi @moyin
      Can you specify where are the objects created?
      Either you can communicate using signal & slots between mainwindow & view object.

      Yuvaram Aligeti
      Embedded Qt Developer
      : )

      M 3 Replies Last reply
      1
      • yuvaramY yuvaram

        Hi @moyin
        Can you specify where are the objects created?
        Either you can communicate using signal & slots between mainwindow & view object.

        M Offline
        M Offline
        moyin
        wrote on last edited by
        #3

        @yuvaram
        hi thnks for rply,
        i hav all objects in mainwindow and view is having only a tableview where i need to push the data extracted from mainwindow gui.
        please rply ASAP

        yuvaramY 1 Reply Last reply
        0
        • M moyin

          @yuvaram
          hi thnks for rply,
          i hav all objects in mainwindow and view is having only a tableview where i need to push the data extracted from mainwindow gui.
          please rply ASAP

          yuvaramY Offline
          yuvaramY Offline
          yuvaram
          wrote on last edited by
          #4

          @moyin
          use signal & slots to communicate
          i mean, emit signal from view to mainwindow.
          If provide ur code, its easy to show.

          Yuvaram Aligeti
          Embedded Qt Developer
          : )

          1 Reply Last reply
          0
          • yuvaramY yuvaram

            Hi @moyin
            Can you specify where are the objects created?
            Either you can communicate using signal & slots between mainwindow & view object.

            M Offline
            M Offline
            moyin
            wrote on last edited by
            #5

            #include "myview.h"
            #include "ui_myview.h"
            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            //#include "view.h"
            #include <QStandardItemModel>
            #include <vector>
            #include "JailHouseCellList.h"
            #include "JailHouseCell.h"
            #include "MemRegion.h"
            #include "IrqChip.h"
            #include "PciDevice.h"
            #include <iostream>
            #include <QBrush>

            using namespace std;

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

            model->setHorizontalHeaderItem(0, new QStandardItem(QString("CELL")));
            model->setHorizontalHeaderItem(1, new QStandardItem(QString("CPU")));
            model->setHorizontalHeaderItem(2, new QStandardItem(QString("MEM REGIONS")));
            model->setHorizontalHeaderItem(3, new QStandardItem(QString("PCI DEVICES")));
            model->setHorizontalHeaderItem(4, new QStandardItem(QString("IRQ CHIPS")));
            //model->horizontalHeaderItem(2)->setText("Apple");
             ui->tableView->setModel(model);
            

            // tableView->setHidden(false);
            for (int i = 0; i < 5; i++)
            ui->tableView->setColumnWidth(i,200);
            ```
            mwin->lineEdit->setText("Root");
            JailHouseCell j (mwin->lineEdit->text()) ;

              //   JailHouseCell j("Root");
                 JailHouseCell j1("redhawk") ;
                 JailHouseCell j2("SEL4") ;
                 PciDevice Y("P");
                 PciDevice Z("q","z",12);
                 MemRegion mz1("m1",1234,1234,39,"qwer|qw");
                 MemRegion mz2("m2",1290,1234,39,"qwer|qw");
                 std::vector<unsigned long> vec{123,345,456};
                 IrqChip iq("iq1",2336655556,555,vec);
                 IrqChip iq1("iq2",2336655557,555,vec);
                 j.add_memRegion(mz1);
                 j.add_memRegion(mz1);
                 j.add_memRegion(mz2);
                 j.add_irqChip(iq);
                 j.add_irqChip(iq);
                 j.add_irqChip(iq1);
                 j.add_pci(Y);
                 j1.add_pci(Z);
            
                 j1.add_memRegion(mz1);
                 j1.add_memRegion(mz1);
                 j1.add_memRegion(mz2);
                 j1.add_irqChip(iq);
                 j1.add_irqChip(iq);
                 j1.add_irqChip(iq1);
            
            
            
                 std::vector<bool> x = {true,true,true,false,false,false};
                 std::vector<bool> y = {false,false,false,true,true,false};
                 std::vector<bool> z = {false,false,false,false,false,true};
                 j.set_cpuIds(x);
                 j1.set_cpuIds(y);
                 j2.set_cpuIds(z);
            
            
                 JailHouseCellList &  JL = JailHouseCellList::getJailHouseCellList();
                 JL.add_cell(j);
                 JL.add_cell(j1);
                 JL.add_cell(j2);
                {
            
                int cell_row=0 , cpu_row=0 , mem_row=0, pci_row = 0, irq_row = 0;
              //  QString color[3] = {"red" , "green", "blue"} ;
                  std::vector<Qt::GlobalColor> color = {Qt::red,Qt::gray, Qt::cyan, Qt::green};
            
                 for( auto cell_itr = JL.get_JailHouseCellItr_begin() ;
                        cell_itr != JL.get_JailHouseCellItr_end();
                        ++cell_itr,++cell_row)
                 {
                     string cell_name = cell_itr->first;
                     auto cell = cell_itr->second;
                     QString q = QString::fromLocal8Bit(cell_name.c_str());
                     cout << cell_name ;
                     //      cout << q ;
                     //autget_cpuIdso cell_info = (cell_itr->second);
            
                     //QModelIndex index
                     //          = model->index(row,0,QModelIndex());
                     // 0 for all data
            
                //     QModelIndex index
                //         = model->index(cell_row,0,QModelIndex());
                     // 0 for all data
              //       model->setData(index, q);
                     auto item = new QStandardItem(q);
                     item->setTextAlignment(Qt::AlignCenter);
            
            //         item->setForeground(Qt::red);
            
                     item->setBackground(color[cell_row]);
                     model->setItem(cpu_row,0,item);
            
                     auto cpu_ids =  cell.get_cpuIds();
                     for(auto & cpu_id : cpu_ids)
                     {
                       QString qcpuid = QString::number(cpu_id) ;
                     //  QModelIndex index = model->index(cpu_row,1,QModelIndex());
                    //   model->setData(index , qcpuid ) ;
                       auto item = new QStandardItem(qcpuid);
                       item->setTextAlignment(Qt::AlignCenter);
            
              //         item->setForeground(Qt::red);
            
                       item->setBackground(color[cell_row]);
                       model->setItem(cpu_row,1,item);
                       ++cpu_row ;
                     }
                     for( auto mem_itr = cell.get_memRegionItr_begin();
                            mem_itr != cell.get_memRegionItr_end();
                            ++mem_itr,++mem_row)
                     {
            
                         auto mem_name = (mem_itr->second).get_name();
                         QString q = QString::fromLocal8Bit(mem_name.c_str());
                      //   QModelIndex index
                      //       = model->index(mem_row,2,QModelIndex());
                         // 0 for all data
                     //    model->setData(index, q);
                         auto item = new QStandardItem(q);
                         item->setTextAlignment(Qt::AlignCenter);
            
                //         item->setForeground(Qt::red);
            
                         item->setBackground(color[cell_row]);
                         model->setItem(mem_row,2,item);
            
                     }
            
                     for( auto pci_itr = cell.get_pciDeviceItr_begin();
                            pci_itr != cell.get_pciDeviceItr_end();
                            ++pci_itr,++pci_row)
                     {
                         auto mem_name = (pci_itr->second).get_name();
                         QString q = QString::fromLocal8Bit(mem_name.c_str());
                      //   QModelIndex index
                      //       = model->index(pci_row,3,QModelIndex());
                         // 0 for all data
                      //   model->setData(index, q);
                         auto item = new QStandardItem(q);
                         item->setTextAlignment(Qt::AlignCenter);
            
                //         item->setForeground(Qt::red);
            
                         item->setBackground(color[cell_row]);
                         model->setItem(pci_row,3,item);
            
                     }
            
                     for( auto irq_itr = cell.get_irqChipItr_begin();
                            irq_itr != cell.get_irqChipItr_end();
                            ++irq_itr,++irq_row)
                     {
            
                         auto mem_name = (irq_itr->second).get_name();
                         QString q = QString::fromLocal8Bit(mem_name.c_str());
                   //      QModelIndex index
                    //           = model->index(irq_row,4,QModelIndex());
                         // 0 for all data
                       //   QVariant Red(QColor(Qt::red));
                    //     model->data(index, QVariant::fromValue(QColor(Qt::red))) ;
                         auto item = new QStandardItem(q);
                         item->setTextAlignment(Qt::AlignCenter);
            
               //         item->setForeground(Qt::red);
            
                         item->setBackground(Qt::red);
                         model->setItem(irq_row,4,item);
                 //        model->setData(index, q);
            
                         //model->setData(Qt::ColorOnly Qt::BackgroundColorRole) ;
                      //   QBrush redBackground(Qt::red);
                       //  model->data(index, redBackground) ;
            
                       //  model->data(index, Red) ;
            
                     }
            
                 }
                 }
            
            }
            
            Myview::~Myview()
            {
                delete ui;
            }
            1 Reply Last reply
            0
            • yuvaramY yuvaram

              Hi @moyin
              Can you specify where are the objects created?
              Either you can communicate using signal & slots between mainwindow & view object.

              M Offline
              M Offline
              moyin
              wrote on last edited by
              #6

              @yuvaram

              this is my myview.cpp where i hav bolded text what i'm trying.

              jsulmJ 1 Reply Last reply
              0
              • M moyin

                @yuvaram

                this is my myview.cpp where i hav bolded text what i'm trying.

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

                @moyin As @yuvaram already said use signals/slot to communicate between different UI parts. See http://doc.qt.io/qt-5.9/signalsandslots.html
                Your view should not know anything about main window.

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

                1 Reply Last reply
                1

                • Login

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