Results 1 to 1 of 1

Thread: Problem with adding same QWidget in differnt tabs of QTabWidget

  1. #1
    Join Date
    Jul 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem with adding same QWidget in differnt tabs of QTabWidget

    HI All,
    I have created 2 tabs in QTabWidget with QListWidget on each tabs.
    Qt Code:
    1. //in CustomListWidget.cpp
    2. #include "CustomListWidget.h"
    3. #include <QDebug>
    4.  
    5. CustomListWidget::CustomListWidget(QString str , QWidget *parent) : m_str(str), QListWidget(parent)
    6. {
    7. listItem = new QListWidgetItem(m_str);
    8. addItem( listItem );
    9. }
    10.  
    11. void CustomListWidget::sendData(QString &str)
    12. {
    13. str = item( 0 )->text();
    14. qDebug()<<"the list Widget text is "<<str;
    15. }
    16.  
    17. // in CTestDlg.cpp
    18. CTestDlg::CTestDlg(QWidget *parent) : QDialog(parent), ui(new Ui::CTestDlg)
    19. {
    20. ui->setupUi(this);
    21. for(int i =1; i<= 2 ; i++ )
    22. {
    23.  
    24. customeListWidget = new CustomListWidget(QString::number(i) );
    25.  
    26. connect( this , SIGNAL(getData(QString&)), customeListWidget, SLOT(sendData(QString&)));
    27. ui->tabWidget->addTab( customeListWidget, QString("TAB").append(QString::number(i) ) );
    28. }
    29. }
    30.  
    31. void CTestDlg::on_pushButton_clicked()
    32. {
    33. QString data;
    34. emit getData( data);
    35. qDebug()<<"the Data value is "<<data;
    36. }
    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 ??
    Last edited by Player; 14th October 2011 at 10:44.

Similar Threads

  1. QTabWidget problem
    By alan lenton in forum Qt Programming
    Replies: 5
    Last Post: 25th July 2016, 16:16
  2. Replies: 6
    Last Post: 21st August 2013, 12:53
  3. QTabWidget problem
    By hnfmr in forum Qt Programming
    Replies: 4
    Last Post: 25th February 2011, 15:10
  4. QTabWidget problem
    By Strongoloid in forum Newbie
    Replies: 2
    Last Post: 10th September 2009, 20:38
  5. QTabWidget - problem with resizing
    By moowy in forum Qt Programming
    Replies: 5
    Last Post: 14th September 2006, 14:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.