It's real easy. There are two different counters, and you're connecting to the wrong one.
The Counter
instance in main()
, the one that you connect to, is never shown (you don't call its show()
method after all!). You need to connect to the instance that is created in this line: tabWidget->addTab(new Counter(), tr("Counter"));
One solution would be do the connection in MainWindow()
:
Counter * counter = new Counter();
QObject::connect(counter, SIGNAL(textChanged(QString)), SLOT(updateWidgets(QString)));
QTabWidget *tabWidget = new QTabWidget;
tabWidget->addTab(counter, tr("Counter"));
layout->addWidget(tabWidget,1,0);
This also illustrates why minimal examples should really be minimal. Were you to continue working on minimization, you'd have found the bug. Essentially, you can delete the lines below from main()
without any change in behavior: this would be a dead giveaway that the counter you think of is not the one.
Counter m;
QObject::connect(&m, SIGNAL(textChanged(QString)), &s,SLOT(updateWidgets(QString)));