Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] qtcpserver and qmainwindow on the constructor



  • 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),@



  • 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.



  • 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



  • 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



  • 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/.



  • 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.



  • 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.



  • [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.


Log in to reply