PDA

View Full Version : How to connect two Tabs in Applicatin?



mandarinka
23rd February 2011, 17:09
Hello.
I have an Application with two Tabs:
- Tab1 (described in tab1.h file) has a QLineEdit widget.
- Tab2 (described in tab2.h file) has a QTableWidget widget.
They are added to Application in tabDialog.h file like this:


tabWidget->addTab(Tab1,"Tab1");
tabWidget->addTab(Tab2,"Tab2");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(tabWidget);
setLayout(layout);

When user run my Application, text in QTableWidgetItem (in Tab2 Table) have to be changed when user press "Enter" in QLineEdit widget (in Tab1).

Could you please give me some idea how and where to connect SIGNAL(returnPressed()) from Tab1 with public slot from Tab2?

stampede
24th February 2011, 00:00
They are added to Application in tabDialog.h (...)
Why are you creating your objects in a header ? And where exactly is the code called ? Is it inline constructor ?
About connection : connect tabs once after adding them to widget:

tabWidget->addTab(Tab1,"Tab1");
tabWidget->addTab(Tab2,"Tab2");
connect( Tab1, SIGNAL(returnPressed()), Tab2, SLOT(publicSlotFromTab2()) );
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(tabWidget);
setLayout(layout);

mandarinka
24th February 2011, 20:20
Why are you creating your objects in a header ?
I create them in .cpp files. I have .h and .cpp files, as it have to be.

And where exactly is the code called ?
In main.cpp like this:

int main(int argc,char *argv[])
{
QApplication app(argc,argv);
tabDialog tabdialog;
return tabdialog.exec();
}

connect( Tab1, SIGNAL(returnPressed()), Tab2, SLOT(publicSlotFromTab2()) );
This does not work. Tab2 in my Application does not change it's Table when user press "Enter" in QLineEdit in Tab1. Maybe I have to push Tab2 to "redraw" itself somehow? But how?

stampede
24th February 2011, 20:35
This does not work
You mean that signal is not delivered to slot ? Try to see if connection call is ok:

bool status = connect(Tab1, ... );
qDebug() << "connection status: " << status;
Add some qDebugs in the slot itself as well and see if you can see them after pressing "return".