PDA

View Full Version : (Callback API) and (Qt - SIGNAL/SLOT)



pytro
8th March 2007, 15:06
Is it possivel to derived Qt Project from a callback API and link it to:
connect(this, SIGNAL(callback_api_function), this, SLOT(processData_to_tablewidget));

I just want to get the event from the "callback_API" and data parameter, and providing it to a tablewidget.

Thanks in advance.

wysota
8th March 2007, 15:08
No, the signal has to be a Qt signal. You might register a callback from the callback api and there either call the slot directly or use a dummy QObject that will emit the signal for you.

pytro
8th March 2007, 15:39
class GuiApp : public QMainWindow, public GPListener( callback API-Class), public Thread

public:
void newPeer (const char *pszNodeUUID); // implemented on GPListener
...
private slots:
void processPeerUpdate(QString p);
...
};

inline void GuiApp::newPeer (const char *pszNodeUUID)
{
emit processPeerUpdate(pszNodeUUID);
}


Gives me a run time Error when:

ui.tableWidget->setItem(0,0,pszNodeUUID);

I can't understand the register process.. is it possible to explain it with more detail please.

wysota
8th March 2007, 17:19
What is the error?

pytro
8th March 2007, 19:56
It is on Release mode, i can't build Qt in Debug mode on Runtime.
The process is:

Image 1 (http://img69.imageshack.us/my.php?image=qt1ya6.jpg) - It reveals that the program is running with no problems; and is waiting for a newpeer.
Image 2 (http://img69.imageshack.us/my.php?image=qt2ek1.jpg) - On the moment i launch the other peer/program, this error ocorrs.
Image 3 (http://img69.imageshack.us/my.php?image=qt3ab4.jpg) - After the click on break button.

When i debug manually, it passes all functions but only when is going to post "pszNodeUUID" on the tablewidget, the error appears.

jacek
8th March 2007, 20:23
What is that Thread class? Aren't you accessing the GUI from a non-GUI thread?

pytro
8th March 2007, 21:37
hi, not using it @ll now, no problems with that.
Here is little history of my Qt work, working perfectly:
image 1 (http://img104.imageshack.us/my.php?image=asd0dk7.jpg) - main.
image 2 (http://img104.imageshack.us/my.php?image=asd1wz9.jpg) - connect(..).
image 3 (http://img104.imageshack.us/my.php?image=asd2qz9.jpg) - processOneThing invoked to update tablewidget.
image 4 (http://img104.imageshack.us/my.php?image=asd3np5.jpg) - postEvent to invoke customEvent ( on image 5 ).
image 5 (http://img104.imageshack.us/my.php?image=asd4er7.jpg) - tablewidget updated.

video (http://img104.imageshack.us/my.php?image=callbackub0.swf) - A little demo video..

jacek
8th March 2007, 21:48
What is the value of pszNodeUUID (in hex)?

wysota
8th March 2007, 21:56
image 1 (http://img104.imageshack.us/my.php?image=asd0dk7.jpg) - main.
image 2 (http://img104.imageshack.us/my.php?image=asd1wz9.jpg) - connect(..).
image 3 (http://img104.imageshack.us/my.php?image=asd2qz9.jpg) - processOneThing invoked to update tablewidget.
image 4 (http://img104.imageshack.us/my.php?image=asd3np5.jpg) - postEvent to invoke customEvent ( on image 5 ).
image 5 (http://img104.imageshack.us/my.php?image=asd4er7.jpg) - tablewidget updated.

video (http://img104.imageshack.us/my.php?image=callbackub0.swf) - A little demo video..

Could you in future please post the code in textual form instead of placing external images? Images come and go whereas the text would remain here as others might face simmilar problems in future and would benefit from this thread. And besides, such images make the thread less readable. Thank you.

pytro
8th March 2007, 22:08
@jacek
Sorry, how do i do that(reading in hex) - the working application or the other?
@wysota
Ok i'll do that, sorry.

jacek
8th March 2007, 22:32
Sorry, how do i do that(reading in hex)
Just print it on the console using qDebug().


the working application or the other?
The non-working one.

pytro
8th March 2007, 23:06
Going to do that tomorrow morning.. thanks for the help!

pytro
9th March 2007, 09:44
Just print it on the console using qDebug().


The non-working one.

It is a Qt Application, not a console application. :confused:


inline void GuiApp::newPeer (const char *pszNodeUUID)
{
processPeerUpdate("0 3"); // no parameters passed i.e pszNodeUUID..
}


Same problem.. ocorrs. :crying:

wysota
9th March 2007, 10:16
It is a Qt Application, not a console application. :confused:

Add CONFIG+=console to your .pro file, rerun qmake and rebuild the application.

jacek
9th March 2007, 13:57
processPeerUpdate("0 3"); // no parameters passed i.e pszNodeUUID..
[...]
Same problem.. ocorrs. :crying:
Then the problem might be inside processPeerUpdate(). Could you post its code?

pytro
9th March 2007, 15:39
The app collapses here:

inline const QString operator+(const QString &s1, const char *s2)
{ QString t(s1); t += QString::fromAscii(s2); return t; }

ProcessPeerUpdate()

void GuiApp::processPeerUpdate(QString h)
{
QStringList d = h.split(" ");
e = new DataUpdateEvent(d);
qApp->postEvent(this, e);
}


void GuiApp::customEvent(QEvent *e)
{
QStringList i;
if ( e->type() == 65432 ) {
DataUpdateEvent* ce = (DataUpdateEvent*)e;
i = ce->data();
}
setValue(i);
}


class DataUpdateEvent : public QCustomEvent
{
public:
DataUpdateEvent(QStringList i)
: QCustomEvent( 65432 ), n(i) {}

QStringList data() { return n; }

private:
QStringList n;

public:
~DataUpdateEvent(void)
{
}
};

pytro
9th March 2007, 16:50
Problem Solved.. Thanks all:cool:

jacek
9th March 2007, 18:39
Problem Solved..
What was the problem?

pytro
13th March 2007, 16:03
Sorry for the late feedback.
Well the problem had ramifications :o...
The listenner (i.e Callback API) wasn't correcty initialized inside Qt App,
and the last error one was easy.. the "tablewidget update" setText with null values :p.

Thanks again.

jacek
13th March 2007, 20:14
The listenner (i.e Callback API) wasn't correcty initialized inside Qt App,
and the last error one was easy.. the "tablewidget update" setText with null values :p.
I see. In such case valgrind's memcheck might be the right tool to identify the problem.