August 21, 2011

kalster kalster
Lab Rat
315 posts

[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?

  1. class ChatterBoxServer : public QTcpServer, public QMainWindow
  2.  
  3. MainWindow::MainWindow(QWidget *parent) :
  4.     QMainWindow(parent),QTcpServer(parent),

7 replies

August 21, 2011

Franzk Franzk
Lab Rat
830 posts

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.

 Signature 

“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

August 21, 2011

kalster kalster
Lab Rat
315 posts

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

August 21, 2011

octal octal
Lab Rat
74 posts

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

August 21, 2011

Rahul Das Rahul Das
Robot Herder
357 posts

Kalster , you have already raised a question regarding this. Please check the work around i have posted in your other thread [developer.qt.nokia.com].

 Signature 

——————————-

    Rahul Das

——————————-

August 21, 2011

Andre Andre
Area 51 Engineer
6031 posts

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:

  1. class ChatterBoxServer : public QTcpServer, public QMainWindow
  2.  
  3. MainWindow::MainWindow(QWidget *parent) :
  4.     QMainWindow(parent),QTcpServer(parent)

but should instead do something like this:

  1. class ChatterBoxServer : public QTcpServer
  2. {
  3. //...
  4. }
  5.  
  6. class ChatterBoxServerUi: public QMainWindow
  7. {
  8. public:
  9.    ChatterBoxServerUi (ChatterBoxServer* server, QWidget* parent=0);
  10. //...
  11.  
  12. private:
  13.    ChatterBoxServer* m_server;
  14. }

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

August 22, 2011

kalster kalster
Lab Rat
315 posts

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.

August 22, 2011

kalster kalster
Lab Rat
315 posts
Rahul Das wrote:
Kalster , you have already raised a question regarding this. Please check the work around i have posted in your other thread [developer.qt.nokia.com].

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.

 
  ‹‹ Correct Suppression Valgrind : Fedora 14 i686      [SOLVED] what signal and slot for this server? ››

You must log in to post a reply. Not a member yet? Register here!