[Solved] Class derived by Qt without Q_Widget
I am currently working an client server communication. The GUI is written in Qt with many widgets, but I want to create the server side. I implemmented a controller class, that has a QTcpServer member. So, what I want to to is give my controller a slot, to which i can connect the newconnection() signal.
Therefore, my controller has to be derived from some type of Qt class, but Q_Widget does not seem to be reasonable, because on server wide I would like to stick with console application.
There is no Q_Widget class in Qt, so you are safe ;)
More seriously, though, all you need to use the signals and slots mechanism (together with the whole meta object system and other goodies) is to derive from QObject class. There is no need to include any gui stuff.
To my understanding, in order to use Signals and Slots with your own class, you need at least to derive from QObject and add the Q_OBJECT macro (maybe that's what you meant?) to the private section of your class declaration. As soon as you do that, you will also need to run MOC on your class' header file and compile the generated .cpp file into your application.
Just derive from QObject and you're ready for the signal/slots etc. Be aware that the first derived class must be QObject if multiple classes are derived.
And, you want to use QCoreApplication rather than QApplication...
@int main(int argc, char *argv)
QCoreApplication App(argc, argv);
Hi, basically it works.
My problem was, that I tried to write QTcpSocket etc. as second derived class.
Now I derive directly from QTcpSocket and my own class and it works in general.