Widget Server Client problem
-
Hello everybody, I have problem with the Server code of my widget.
It says : " expected class-name before '{' token "
And I searched over the internet but didnt find my solutionHere is the code :
#ifndef HELLOWORLDSERVER_H #define HELLOWORLDSERVER_H #include <QTcpServer> #include "MainWindow.h" class MainWindow; class HelloWorldServer : public QTcpServer { public: Q_OBJECT public: HelloWorldServer(MainWindow* pHelloServer,QObject *parent=0); MainWindow* m_pHelloWindow; private slots: void readyRead(); void disconnected(); protected: void incomingConnection(int socketfd); private: QSet<QTcpSocket*> clients; }; #endif // HELLOWORLDSERVER_H
I hope you will help me, Thank you
-
Hi,
What does
MainWindow.h
look like ?The
Q_OBJECT
macro should be in the private part of your class.Out of curiosity, why does your QTcpServer have to know about your MainWindow ? That smells like tight coupling which is a bad idea.
-
Hi,
What does
MainWindow.h
look like ?The
Q_OBJECT
macro should be in the private part of your class.Out of curiosity, why does your QTcpServer have to know about your MainWindow ? That smells like tight coupling which is a bad idea.
@SGaist Thank you for your answer, I actually took a part of code from the internet.
Here is the the mainwindow.h :
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "HelloWorldServer.h" namespace Ui { class MainWindow; } class HelloWorldServer; class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void addMessage(QString Msg); HelloWorldServer* m_pBoxServer; private slots: void on_pushButtonStart_clicked(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
I tried putting the Q_OBJECT into the private one and it gave me same errors with this one more : QTcpServer was not declared in this scope.
-
@SGaist Thank you for your answer, I actually took a part of code from the internet.
Here is the the mainwindow.h :
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "HelloWorldServer.h" namespace Ui { class MainWindow; } class HelloWorldServer; class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void addMessage(QString Msg); HelloWorldServer* m_pBoxServer; private slots: void on_pushButtonStart_clicked(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
I tried putting the Q_OBJECT into the private one and it gave me same errors with this one more : QTcpServer was not declared in this scope.
@lolilol78 Basically the widget for the client works fine (entering the ip adresse, the port, and connect push button.)
but the server is stuck
-
Did you add
QT += network
to your .pro file ?Your HelloWorldServer shouldn't know anything about MainWindow. You should have slots there that you will connect to the MainWindow appropriate signals.
-
Did you add
QT += network
to your .pro file ?Your HelloWorldServer shouldn't know anything about MainWindow. You should have slots there that you will connect to the MainWindow appropriate signals.
-
Then can you show the complete error log ?
When you have
XXX was not declared in this scope
, it usually means that you didn't include the header which provides that class.I mean that your
HelloWorldServer
shouldn't need to know where from its data are coming. Just give it an interface that allows to set whatever parameter it needs. -
Then can you show the complete error log ?
When you have
XXX was not declared in this scope
, it usually means that you didn't include the header which provides that class.I mean that your
HelloWorldServer
shouldn't need to know where from its data are coming. Just give it an interface that allows to set whatever parameter it needs. -
You have circular dependencies.
-
Then can you show the complete error log ?
When you have
XXX was not declared in this scope
, it usually means that you didn't include the header which provides that class.I mean that your
HelloWorldServer
shouldn't need to know where from its data are coming. Just give it an interface that allows to set whatever parameter it needs. -
No, it means you are including
MainWindow.h
inHelloWorldServer.h
and thenHelloWorldServer.h
inMainWindow.h