HI All,
I have created 2 tabs in QTabWidget with QListWidget on each tabs.
//in CustomListWidget.cpp
#include "CustomListWidget.h"
#include <QDebug>
{
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()
{
emit getData( data);
qDebug()<<"the Data value is "<<data;
}
//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;
}
To copy to clipboard, switch view to plain text mode
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 ??
Bookmarks