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] qtcpserver and qmainwindow on the constructor
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] qtcpserver and qmainwindow on the constructor

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 3.8k 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    I have this server project that i am trying to create a form for it. in the mainwindow construction i have Qmainwindow as parent. the problems is that the tcpserver commands do not work now. i set the QTcpServer in the constructor as in the code below. now i am getting a bunch of errors. how to put the QTcpServer and the Qmainwindow on the constructor line without getting any errors. is this possible? do i need to put something into the header?

    @class ChatterBoxServer : public QTcpServer, public QMainWindow

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),QTcpServer(parent),@

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      You are trying to multiple inherit from two QObjects. That is not going to work for a whole bunch of reasons. The most important thing is the design choice though. Your main window has no business being a server. If it controls one, it should have a server.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #3

        it does have a server. the problem is that i need the forms too. how can i have them both? if i have QtcpServer then i can't show the main form

        1 Reply Last reply
        0
        • O Offline
          O Offline
          octal
          wrote on last edited by
          #4

          bq. if i have QtcpServer then i can’t show the main form

          What ? Why couldn't you show the main form ? Just put the QTcpServer as an attribute of your MainWindow

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rahul Das
            wrote on last edited by
            #5

            Kalster , you have already raised a question regarding this. Please check the work around i have posted in your other "thread":http://developer.qt.nokia.com/forums/viewthread/9006/.


            Declaration of (Platform) independence.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              That is not the same question, if you ask me.

              kalster, what Frankz and octal are trying to tell you, is that you should not do this:
              @
              class ChatterBoxServer : public QTcpServer, public QMainWindow

              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),QTcpServer(parent)
              @

              but should instead do something like this:
              @
              class ChatterBoxServer : public QTcpServer
              {
              //...
              }

              class ChatterBoxServerUi: public QMainWindow
              {
              public:
              ChatterBoxServerUi (ChatterBoxServer* server, QWidget* parent=0);
              //...

              private:
              ChatterBoxServer* m_server;
              }
              @

              That is: your ChatterBoxServer class is a subclass of just QTcpServer, and your UI for it is a subclass of QMainWindow that in its constructor (or in some other way) takes a pointer to an instance of a ChatterBoxServer instance.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kalster
                wrote on last edited by
                #7

                thank you Andre. i understand now. i never knew that i could use two classes like that in your example. your post helped me a lot. I marked this topic as solved.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #8

                  [quote author="Rahul Das" date="1313916068"]Kalster , you have already raised a question regarding this. Please check the work around i have posted in your other "thread":http://developer.qt.nokia.com/forums/viewthread/9006/.[/quote]

                  Rahul Das is correct. i really do not need this topic anymore because he helped me out in the other topic. he basically solved two topics in one post.

                  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