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 pass data from one tab to another.
QtWS25 Last Chance

How to pass data from one tab to another.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 788 Views
  • 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.
  • P Offline
    P Offline
    pavel213
    wrote on last edited by
    #1

    Hello Everyone,
    I am learning Qt and stuck on below problem.
    I have a gui which have more than 10 tabs. I have created one new tab. In that new tab I am using QtLineEdit. I want to fill this QtLineEdit with data from another tab's QTableView.
    Any help would be appreciated.
    Thanks.

    jsulmJ CP71C 2 Replies Last reply
    0
    • P pavel213

      Hello Everyone,
      I am learning Qt and stuck on below problem.
      I have a gui which have more than 10 tabs. I have created one new tab. In that new tab I am using QtLineEdit. I want to fill this QtLineEdit with data from another tab's QTableView.
      Any help would be appreciated.
      Thanks.

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

      @pavel213 Well, you have access to all your widgets in same parent widget via ui->, so simply access what is needed using ui->NAME_OF_WIDGET_OBJECT.

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

      1 Reply Last reply
      1
      • P Offline
        P Offline
        pavel213
        wrote on last edited by
        #3

        @jsulm Thanks for reply. Would you please elaborate your answer. I don't have much experience in qt.

        jsulmJ 1 Reply Last reply
        0
        • P pavel213

          @jsulm Thanks for reply. Would you please elaborate your answer. I don't have much experience in qt.

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

          @pavel213 Do you use QtDesigner to design your UI?
          If you do, then you can access ALL your widgets using ui->:

          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
              ui->lineEdit->setText("Some text");
          }
          

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

          1 Reply Last reply
          2
          • P pavel213

            Hello Everyone,
            I am learning Qt and stuck on below problem.
            I have a gui which have more than 10 tabs. I have created one new tab. In that new tab I am using QtLineEdit. I want to fill this QtLineEdit with data from another tab's QTableView.
            Any help would be appreciated.
            Thanks.

            CP71C Offline
            CP71C Offline
            CP71
            wrote on last edited by
            #5

            @pavel213
            Hi,
            well, you have several ways to do this, much depends on the type of data ( temporary data, data that your core application uses, ... ).

            As jsulm says you have access to all widgets, so from the parent you can get data from a tab and give them to other tab/tabs.
            MyData data = ui->tab1->getMyData()
            ui->tab2->setMyData(data)

            Via signals, when data changes you can emit a signal with the new value/s.
            connect( ui->tab1, SIGNAL( myDataChange( MyData ), ui->tab2, SLOT( newValueData(MyData) ); // For example I use old style connect

            Via data manager, if your data is data useful for your core application.
            In the tab1: CoreDataManager->setMyData( data );
            In the tab2: data = CoreDataManager->getMyData( );

            and so on.

            As I already say, much depends on the type of data and how you use them.

            1 Reply Last reply
            3
            • P Offline
              P Offline
              pavel213
              wrote on last edited by
              #6

              Gui is built in VS 2015 and qt 5.9.9.

              Following is the code snippet.
              From this tab "MultitranpondersTab" i want to pick data "a_list".

              void MultiTranspondersTab::cycle()
              {
                  QByteArray answer, uid;
              	bool gotAnswer;
              	ST25R3911ComError err;
              	QList<Card*> card_list;
              
              	gotAnswer = true;
              
              	err = this->com->antennaEnableRFField(true);
                  if (err)
                  {
                      emit mainWindowDisplayMessage("ext field detected, not polling");
                      goto end_scan;
                  }
              
              	onTriggerProgressBar();
              	SleepThread::msleep(10);
              
              	if(this->isoA_cb->isChecked())
              	{
              		int counter = 10;
              		QList<Iso14443aCard> a_list;
              
                      com->kovioInitialise();
                      err = com->kovioRead(uid);
                      com->kovioDeinit(true);
                      if (ST25R3911ComError::NoError == err)
                      {
                          if (uid.size() > 0) {
                              // avoid the "kovio situation"
                              Card *card = new Card(uid, QString("Kovio BC"));
                              card_list.append(card);
                          }
                          else
                          {
                              emit mainWindowDisplayMessage("problem receiving data..");
                          }
                          goto end_scan; // no sense to continue to other protocols since Kovio barcode will screw all other communications
                      }
                      this->com->iso14443aInit();
              		onTriggerProgressBar();
              		do 
              		{
              			counter--;
              			gotAnswer = false;
                          int list_size = a_list.size(); /* list_size is a Workaround for early AS3953 versions which did not recognize HLTA command */
                          if (itsAnalogState)
                          {
                              SleepThread::msleep(delay_sb->value());
                          }
              			err = this->com->iso14443aREQA(&a_list, uid);
              
              			if(err == ST25R3911ComError::NoError && a_list.size()>list_size)
              			{
              

              and following is the tab where i want to use it:

              WiegandTab::WiegandTab(ST25R3911Communication* com, QWidget *parent)
              	: QWidget(parent)
              	, itsCom(com)
              	, itsCurrentCardRow(0)
              {
              	this->setupUi(this);
              	
               
              
                  
              	this->txrx_pb->setEnabled(true);
              }
              
              void WiegandTab::on_txrx_pb_clicked(bool clicked)
              {
              	/*if (felicaCardsTw->rowCount() < 0)
              		return;*/
              	WiegandTab wTabObj;
              	ST25R3911ComError err;
              	QByteArray wiegandData, fc, cid, rx;
              	const QByteArray	tempCard;
              	int w_frmt;
              	bool ok;
              	QString format = this->comboBox->currentText();
              	
              	w_frmt = format.split(" ").last().toInt(&ok, 16);
              
              #if QT_VERSION < 0x050000
              	fc = QByteArray::fromHex(this->txbytes_le->text().toAscii());
              	cid = QByteArray::fromHex(this->txbytes_le_2->text().toAscii());
              #else
              	fc = QByteArray::fromHex(this->txbytes_le->text().toLatin1());
              	cid = QByteArray::fromHex(this->txbytes_le_2->text().toLatin1());
              #endif
              	
              	//some where here i want to use "a_list" 
                      // basically want to put "a_list" data in  "txbytes_le_2"
              
              	/*if (item && this->idm_box->isChecked())
              	{
              #if QT_VERSION < 0x050000
              		idm = QByteArray::fromHex(item->text().toAscii());
              #else
              		idm = QByteArray::fromHex(item->text().toLatin1());
              #endif
              	}*/
              
              	//qDebug() << "wiegandTxRxNBytes() idm =" << idm.toHex();
              
              	wiegandData.append(w_frmt);
              	wiegandData.append(fc);
              	wiegandData.append(cid);
              
              	qDebug() << "wiegandTxRxNBytes() tx =" << wiegandData.toHex();
              
              	err = itsCom->wiegandTxRxNBytes(wiegandData, rx);
              	if (err == ST25R3911ComError::NoError)
              	{
              		//rxbytes_le->setText(rx.toHex());
              	}
              	emit mainWindowDisplayMessage(QString("wiegandTxRxNBytes[%1]").arg(itsCom->decodeFWError(err)) + wiegandData.toHex() + "->" + rx.toHex());
              }
              
              
              CP71C 2 Replies Last reply
              0
              • P pavel213

                Gui is built in VS 2015 and qt 5.9.9.

                Following is the code snippet.
                From this tab "MultitranpondersTab" i want to pick data "a_list".

                void MultiTranspondersTab::cycle()
                {
                    QByteArray answer, uid;
                	bool gotAnswer;
                	ST25R3911ComError err;
                	QList<Card*> card_list;
                
                	gotAnswer = true;
                
                	err = this->com->antennaEnableRFField(true);
                    if (err)
                    {
                        emit mainWindowDisplayMessage("ext field detected, not polling");
                        goto end_scan;
                    }
                
                	onTriggerProgressBar();
                	SleepThread::msleep(10);
                
                	if(this->isoA_cb->isChecked())
                	{
                		int counter = 10;
                		QList<Iso14443aCard> a_list;
                
                        com->kovioInitialise();
                        err = com->kovioRead(uid);
                        com->kovioDeinit(true);
                        if (ST25R3911ComError::NoError == err)
                        {
                            if (uid.size() > 0) {
                                // avoid the "kovio situation"
                                Card *card = new Card(uid, QString("Kovio BC"));
                                card_list.append(card);
                            }
                            else
                            {
                                emit mainWindowDisplayMessage("problem receiving data..");
                            }
                            goto end_scan; // no sense to continue to other protocols since Kovio barcode will screw all other communications
                        }
                        this->com->iso14443aInit();
                		onTriggerProgressBar();
                		do 
                		{
                			counter--;
                			gotAnswer = false;
                            int list_size = a_list.size(); /* list_size is a Workaround for early AS3953 versions which did not recognize HLTA command */
                            if (itsAnalogState)
                            {
                                SleepThread::msleep(delay_sb->value());
                            }
                			err = this->com->iso14443aREQA(&a_list, uid);
                
                			if(err == ST25R3911ComError::NoError && a_list.size()>list_size)
                			{
                

                and following is the tab where i want to use it:

                WiegandTab::WiegandTab(ST25R3911Communication* com, QWidget *parent)
                	: QWidget(parent)
                	, itsCom(com)
                	, itsCurrentCardRow(0)
                {
                	this->setupUi(this);
                	
                 
                
                    
                	this->txrx_pb->setEnabled(true);
                }
                
                void WiegandTab::on_txrx_pb_clicked(bool clicked)
                {
                	/*if (felicaCardsTw->rowCount() < 0)
                		return;*/
                	WiegandTab wTabObj;
                	ST25R3911ComError err;
                	QByteArray wiegandData, fc, cid, rx;
                	const QByteArray	tempCard;
                	int w_frmt;
                	bool ok;
                	QString format = this->comboBox->currentText();
                	
                	w_frmt = format.split(" ").last().toInt(&ok, 16);
                
                #if QT_VERSION < 0x050000
                	fc = QByteArray::fromHex(this->txbytes_le->text().toAscii());
                	cid = QByteArray::fromHex(this->txbytes_le_2->text().toAscii());
                #else
                	fc = QByteArray::fromHex(this->txbytes_le->text().toLatin1());
                	cid = QByteArray::fromHex(this->txbytes_le_2->text().toLatin1());
                #endif
                	
                	//some where here i want to use "a_list" 
                        // basically want to put "a_list" data in  "txbytes_le_2"
                
                	/*if (item && this->idm_box->isChecked())
                	{
                #if QT_VERSION < 0x050000
                		idm = QByteArray::fromHex(item->text().toAscii());
                #else
                		idm = QByteArray::fromHex(item->text().toLatin1());
                #endif
                	}*/
                
                	//qDebug() << "wiegandTxRxNBytes() idm =" << idm.toHex();
                
                	wiegandData.append(w_frmt);
                	wiegandData.append(fc);
                	wiegandData.append(cid);
                
                	qDebug() << "wiegandTxRxNBytes() tx =" << wiegandData.toHex();
                
                	err = itsCom->wiegandTxRxNBytes(wiegandData, rx);
                	if (err == ST25R3911ComError::NoError)
                	{
                		//rxbytes_le->setText(rx.toHex());
                	}
                	emit mainWindowDisplayMessage(QString("wiegandTxRxNBytes[%1]").arg(itsCom->decodeFWError(err)) + wiegandData.toHex() + "->" + rx.toHex());
                }
                
                
                CP71C Offline
                CP71C Offline
                CP71
                wrote on last edited by CP71
                #7

                @pavel213
                If I have well understood your code a_list is a local QList (MultiTranspondersTab class), it is declared in the function body. So the only way I see is sending a copy of data to another tab (WiegandTab class) via connect, see the previous post.

                1 Reply Last reply
                0
                • P pavel213

                  Gui is built in VS 2015 and qt 5.9.9.

                  Following is the code snippet.
                  From this tab "MultitranpondersTab" i want to pick data "a_list".

                  void MultiTranspondersTab::cycle()
                  {
                      QByteArray answer, uid;
                  	bool gotAnswer;
                  	ST25R3911ComError err;
                  	QList<Card*> card_list;
                  
                  	gotAnswer = true;
                  
                  	err = this->com->antennaEnableRFField(true);
                      if (err)
                      {
                          emit mainWindowDisplayMessage("ext field detected, not polling");
                          goto end_scan;
                      }
                  
                  	onTriggerProgressBar();
                  	SleepThread::msleep(10);
                  
                  	if(this->isoA_cb->isChecked())
                  	{
                  		int counter = 10;
                  		QList<Iso14443aCard> a_list;
                  
                          com->kovioInitialise();
                          err = com->kovioRead(uid);
                          com->kovioDeinit(true);
                          if (ST25R3911ComError::NoError == err)
                          {
                              if (uid.size() > 0) {
                                  // avoid the "kovio situation"
                                  Card *card = new Card(uid, QString("Kovio BC"));
                                  card_list.append(card);
                              }
                              else
                              {
                                  emit mainWindowDisplayMessage("problem receiving data..");
                              }
                              goto end_scan; // no sense to continue to other protocols since Kovio barcode will screw all other communications
                          }
                          this->com->iso14443aInit();
                  		onTriggerProgressBar();
                  		do 
                  		{
                  			counter--;
                  			gotAnswer = false;
                              int list_size = a_list.size(); /* list_size is a Workaround for early AS3953 versions which did not recognize HLTA command */
                              if (itsAnalogState)
                              {
                                  SleepThread::msleep(delay_sb->value());
                              }
                  			err = this->com->iso14443aREQA(&a_list, uid);
                  
                  			if(err == ST25R3911ComError::NoError && a_list.size()>list_size)
                  			{
                  

                  and following is the tab where i want to use it:

                  WiegandTab::WiegandTab(ST25R3911Communication* com, QWidget *parent)
                  	: QWidget(parent)
                  	, itsCom(com)
                  	, itsCurrentCardRow(0)
                  {
                  	this->setupUi(this);
                  	
                   
                  
                      
                  	this->txrx_pb->setEnabled(true);
                  }
                  
                  void WiegandTab::on_txrx_pb_clicked(bool clicked)
                  {
                  	/*if (felicaCardsTw->rowCount() < 0)
                  		return;*/
                  	WiegandTab wTabObj;
                  	ST25R3911ComError err;
                  	QByteArray wiegandData, fc, cid, rx;
                  	const QByteArray	tempCard;
                  	int w_frmt;
                  	bool ok;
                  	QString format = this->comboBox->currentText();
                  	
                  	w_frmt = format.split(" ").last().toInt(&ok, 16);
                  
                  #if QT_VERSION < 0x050000
                  	fc = QByteArray::fromHex(this->txbytes_le->text().toAscii());
                  	cid = QByteArray::fromHex(this->txbytes_le_2->text().toAscii());
                  #else
                  	fc = QByteArray::fromHex(this->txbytes_le->text().toLatin1());
                  	cid = QByteArray::fromHex(this->txbytes_le_2->text().toLatin1());
                  #endif
                  	
                  	//some where here i want to use "a_list" 
                          // basically want to put "a_list" data in  "txbytes_le_2"
                  
                  	/*if (item && this->idm_box->isChecked())
                  	{
                  #if QT_VERSION < 0x050000
                  		idm = QByteArray::fromHex(item->text().toAscii());
                  #else
                  		idm = QByteArray::fromHex(item->text().toLatin1());
                  #endif
                  	}*/
                  
                  	//qDebug() << "wiegandTxRxNBytes() idm =" << idm.toHex();
                  
                  	wiegandData.append(w_frmt);
                  	wiegandData.append(fc);
                  	wiegandData.append(cid);
                  
                  	qDebug() << "wiegandTxRxNBytes() tx =" << wiegandData.toHex();
                  
                  	err = itsCom->wiegandTxRxNBytes(wiegandData, rx);
                  	if (err == ST25R3911ComError::NoError)
                  	{
                  		//rxbytes_le->setText(rx.toHex());
                  	}
                  	emit mainWindowDisplayMessage(QString("wiegandTxRxNBytes[%1]").arg(itsCom->decodeFWError(err)) + wiegandData.toHex() + "->" + rx.toHex());
                  }
                  
                  
                  CP71C Offline
                  CP71C Offline
                  CP71
                  wrote on last edited by CP71
                  #8

                  @pavel213
                  Only for example:

                  In MultiTranspondersTab.h :

                  signals
                  void sendIsoData(QList<Iso14443aCard>);

                  In WiegandTab.h :

                  public slots:
                  void onNewIsoData(QList<Iso14443aCard>);

                  in parent of MultiTranspondersTab.h and onNewIsoData:
                  connect( pMultiTranspondersTab, &MultiTranspondersTab::sendIsoData, pWiegandTab, &WiegandTab::onNewIsoData );

                  In MultiTranspondersTab.cpp
                  somewhere in MultiTranspondersTab::cycle() you have to write emit sendIsoData(a_list);

                  1 Reply Last reply
                  0

                  • Login

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