Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Class derived by Qt without Q_Widget

[Solved] Class derived by Qt without Q_Widget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    curator
    wrote on last edited by
    #1

    Hi all,

    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.

    regards,
    curator

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        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.

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Yup,
          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.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vaquita Tim
            wrote on last edited by
            #5

            And, you want to use QCoreApplication rather than QApplication...

            @int main(int argc, char *argv[])
            {
            QCoreApplication App(argc, argv);
            @

            1 Reply Last reply
            0
            • C Offline
              C Offline
              curator
              wrote on last edited by
              #6

              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.

              regards
              curator

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved