PDA

View Full Version : Can C functions send data to QT Slots in QT5.7 ?



vivekyuvan
29th October 2018, 09:43
Dear Friends

I want to do some trail work for proof of concept of my project.

What I need is I have C source code that needs to communicate with QT slots. I am using QT Creator IDE and QT5.7.


Ex
unsigned int a[100]={ 25, 17 , 10, 6, -5 , -6, -8 , 10, ......... };



I am required to send this array data to QT GUI through Slots, from C source file to QT Slots is that possible?

If possible please someone shows the code snippet in QT that will help me a lot


Thanks

vivekyuvan

d_stranz
29th October 2018, 15:14
Qt is C++ and a slot is no different from any ordinary C++ function. There is no magic.



class MyClass : public QObject
{
Q_OBJECT

// ...

public slots:
void someSlot( size_t n, unsigned int * array )
{
// Do something with array
}

// ...
};

// Usage

MyClass myClass;
unsigned int a[100]={ 25, 17 , 10, 6, -5 , -6, -8 , 10, ......... };

myClass.someSlot( 100, a );


In Qt 5, slots do not even have to be member functions, they can be any C++ function including lambdas.

vivekyuvan
30th October 2018, 05:13
Hi@d_stranz

(Qt is C++ and a slot is no different from any ordinary C++ function. There is no magic. ) Yes I agree but what I want is

I like to implement frontend alone in qt and backend is in C. The backend code was written in C its best to keep the code in C because its a driver code. so now my concern is can I communicate my driver code with frontend QT GUI?

I just read out QDBUS Interprocess communication protocol it suits my application logic?

Please give me any suggestion and show me the code snippet that will helpful


Thanks
vivek

d_stranz
30th October 2018, 15:55
show me the code snippet that will helpful

We are not here to write your applications for you. There are many, many examples and tutorials that come with Qt, and many more on the Internet. I am sure there are some that use the Qt DBUS library. Study them.

As I said, Qt is just a library written in C++, and you can call functions in any other C++ or C library from a C++ program. If you do not understand enough C / C++ to know how to call between C and C++ code, then you need to learn some basic programming skills first.