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. Widget Server Client problem
QtWS25 Last Chance

Widget Server Client problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 1.3k Views
  • 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.
  • L Offline
    L Offline
    lolilol78
    wrote on last edited by
    #1

    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 solution

    Here 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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      2
      • SGaistS SGaist

        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.

        L Offline
        L Offline
        lolilol78
        wrote on last edited by
        #3

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

        L 1 Reply Last reply
        0
        • L lolilol78

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

          L Offline
          L Offline
          lolilol78
          wrote on last edited by
          #4

          @lolilol78 Basically the widget for the client works fine (entering the ip adresse, the port, and connect push button.)

          but the server is stuck

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            L 1 Reply Last reply
            1
            • SGaistS SGaist

              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.

              L Offline
              L Offline
              lolilol78
              wrote on last edited by
              #6

              @SGaist I added it yes .

              What do you mean by shouldnt know anything about?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                L 2 Replies Last reply
                1
                • SGaistS SGaist

                  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.

                  L Offline
                  L Offline
                  lolilol78
                  wrote on last edited by
                  #8

                  @SGaist ok i see. here is the full error log :

                  0_1533849878699_10b4c912-3f25-4df3-85b5-d89e75891d80-image.png

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You have circular dependencies.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    L 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      You have circular dependencies.

                      L Offline
                      L Offline
                      lolilol78
                      wrote on last edited by
                      #10

                      @SGaist dont know about that, i will check the internet and come back to you. thank you for your help SGaist

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        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.

                        L Offline
                        L Offline
                        lolilol78
                        wrote on last edited by
                        #11

                        @SGaist so it means that i have functions related to other .cpp inside my whole program?

                        (sorry it is all new to me)

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          No, it means you are including MainWindow.h in HelloWorldServer.h and then HelloWorldServer.h in MainWindow.h

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2

                          • Login

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