PDA

View Full Version : Problem with adding same QWidget in differnt tabs of QTabWidget



Player
14th October 2011, 10:03
HI All,
I have created 2 tabs in QTabWidget with QListWidget on each tabs.


//in CustomListWidget.cpp
#include "CustomListWidget.h"
#include <QDebug>

CustomListWidget::CustomListWidget(QString str , QWidget *parent) : m_str(str), QListWidget(parent)
{
listItem = new QListWidgetItem(m_str);
addItem( listItem );
}

void CustomListWidget::sendData(QString &str)
{
str = item( 0 )->text();
qDebug()<<"the list Widget text is "<<str;
}

// in CTestDlg.cpp
CTestDlg::CTestDlg(QWidget *parent) : QDialog(parent), ui(new Ui::CTestDlg)
{
ui->setupUi(this);
for(int i =1; i<= 2 ; i++ )
{

customeListWidget = new CustomListWidget(QString::number(i) );

connect( this , SIGNAL(getData(QString&)), customeListWidget, SLOT(sendData(QString&)));
ui->tabWidget->addTab( customeListWidget, QString("TAB").append(QString::number(i) ) );
}
}

void CTestDlg::on_pushButton_clicked()
{
QString data;
emit getData( data);
qDebug()<<"the Data value is "<<data;
}


Here when i do click the push button by selecting TAb1 or TAb2...

I am always getting the output of

==============================

the list Widget text is “1”
the list Widget text is“2”
the Data value is “2”

Whether i am missing anything here? and may i know..why this duplication is occuring ??