PDA

View Full Version : Unable to detect clicked signal on top layers



rawfool
16th June 2013, 18:52
I'm having a button on a widget (homeWidget). The homeWidget is in a stackedwidget which is set as central widget for a main window.
Now I need to detect a button click signal from homeWidget and trigger an event in CWorker(a subclass of qobject, which I' running as a thread in mainwindow).

So here I have a clicked signal from homeWidget to centralwidget, on this signal, I'm emitting another signal in centralWidget which is received in mainwindow and connected to a slot in CWorker. Here mainwindow acts as a moderator.

After doing this, I'm trying to check the clicked signal in CWorker slot using a debug message. I'm not getting debug message in the output. I'm unable to find out why the message isn't getting printed. Please help me solve the issue. Thank you.

Santosh Reddy
16th June 2013, 19:02
Are there any warnings in application output?

rawfool
16th June 2013, 19:04
No warnings!!

I'm able to catch the signal from CWorker then pass it on till homeWidget. But the otherway isn't working.

Santosh Reddy
16th June 2013, 19:12
I'm able to catch the signal from CWorker then pass it on till homeWidget. But the otherway isn't working.
Then it makes me think that signal and slot are not connected, and hence not being called. Show us somthing :)

anda_skoa
16th June 2013, 19:23
When you say CWorker is in a secondary thread, have done that using QObject::moveToThread() or by creating it inside run()?
Is the secondary thread's event loop running?

Cheers,
_

rawfool
16th June 2013, 19:30
Pls find the flow of signal from homeWidget to slot in cworker:

In chomewidget.cpp:

connect(m_pbScan, SIGNAL(clicked()), this, SIGNAL(scanBtnClicked())); // this connect is in constructor of homeWidget.cpp

In centralWidget.cpp:

homeWidget = new CHomePage();
connect(homeWidget, SIGNAL(scanBtnClicked()), this, SIGNAL(scanBtnClicked())); // again in constructor
// used similar name for signal in centralWidget.cpp again

In cmainwindow.cpp

centralWidget = new CCentralWidget(); // QStackedWidget
connect(centralWidget, SIGNAL(scanBtnClicked()), worker, SLOT(onScanBtnClick()));// in constructor

In cworker.h

public slots:
void onScanBtnClick();

In cworker.cpp

void CWorker::onScanBtnClick()
{
qDebug("Scan Button Clicked from UI");
}

Thank you.

ChrisW67
17th June 2013, 02:14
What is a CHomePage and what would make it emit scanBtnClicked?

rawfool
17th June 2013, 05:42
When you say CWorker is in a secondary thread, have done that using QObject::moveToThread() or by creating it inside run()?
Is the secondary thread's event loop running?Yes, I did QObject::moveToThread(). I started the secondary thread in qmainwindow.
The slot which I'm trying to call is not in the loop. It need not be in this case.

worker = new CWorker();
thread = new QThread();
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(pollSharedMemory()));
connect(trayIcon, SIGNAL(quitButtonClicked()), thread, SLOT(quit()));
connect(trayIcon, SIGNAL(quitButtonClicked()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
shrdMemorySignals();
thread->start();


What is a CHomePage and what would make it emit scanBtnClicked?CHomePage is one of the widgets on QStackedWidget. QStackedWidget is set as central widget to QMainWindow. So I need to detect the button click signal in CWorker slot (this slot is not running in loop, so need to catch that signal.

Thank you.

anda_skoa
17th June 2013, 13:40
and pollSharedMemory() is not running an infinite loop, right?

Cheers,
_

rawfool
17th June 2013, 13:50
It's in infinite loop: while(1). With 2 secs sleep.
Now Santosh suggested me to use QTimer from mainwindow itself instead by removing while(1). And timer->moveToThread(thread);
As of now it's working fine.

EDIT: BTW Any ideas ?

anda_skoa
17th June 2013, 16:12
It's in infinite loop: while(1). With 2 secs sleep.

Meaning you block the thread's event loop, but the event loop is needed to receive the slot invocation event.

Not sure why you would need a timer though, sounds unrelated.

Cheers,
_

rawfool
17th June 2013, 16:34
I'm polling shared memory content, so I created a slot which check the change in data of shared memory & emits a signal. Based on this signal, I disable/enable some widgets.
And on click events in some widgets, I need to update values of the shared memory (this signal, I wasn't able to receive).
For ore clarity, I've described my architecture in post #1.
Thank you for your interest anda_skoa.

Santosh Reddy
17th June 2013, 21:20
For ore clarity, I've described my architecture in post #1.
That is no where near structure, how can it be architecture? It is a just enough to wear thinking cap.