Reputation: 876
I have an application made in/with Qt. It's an irc client. So basicly I have a listwidget for the contact list and an other for the chat list. I also avec a lineEdit and a button. when i doubleclick on an item, it opens an other tab. Until here, it's good. When the user type /join toto it opens a tab called toto (this is a new channel). The thing is that when I open a new tab, i re-create every widget (lists, lineEdit, button) for this new tab. So when the user type /join toto from a tab, he can't send anything on this tab. But he can do it on the newly created tab.
I've no idea why it's doing this, so if any of you can help me, it's great, thanks :P
Here is the code where i'm creating the new tab. Every var is a class var.
newTab = new QWidget(ui->tabWidget);
pushButton = new QPushButton("Envoyer", newTab);
connect(pushButton, SIGNAL(clicked()), this, SLOT(clicked()));
pushButton->setGeometry(976, 705, 121, 27);
chatListView = new QListView(newTab);
chatListView->setGeometry(10, 10, 891 ,681);
contactListView = new QListWidget(newTab);
contactListView->setGeometry(910, 10, 251, 681);
lineEdit = new QLineEdit(newTab);
lineEdit->setGeometry(10, 705, 891, 27);
connect(lineEdit, SIGNAL(returnPressed()), pushButton, SLOT(click()));
ui->tabWidget->addTab(newTab, name);
Upvotes: 1
Views: 1877
Reputation: 92569
Move all of this code into a custom subclass of a QWidget. Then each time you want to make a new tab, just create a brand new instance of your custom widget.
Note that right now you are constantly referring to class instance attributes instead of brand new objects. You should not be replacing the same newTab
attribute each time. Its most likely breaking your connection references.
You will end up with something like this:
MyTabWidget *tabWidget = new MyTabWidget(this);
connect(tabWidget->pushButton, SIGNAL(clicked()), this, SLOT(clicked()));
connect(tabWidget->lineEdit, SIGNAL(returnPressed()), pushButton, SLOT(click()));
ui->tabWidget->addTab(tabWidget, name);
Upvotes: 2