Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Multi threaded TCP server GUI using Qt widgets application
Forum Updated to NodeBB v4.3 + New Features

Multi threaded TCP server GUI using Qt widgets application

Scheduled Pinned Locked Moved Unsolved Qt 6
16 Posts 3 Posters 2.0k 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.
  • C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 17 Dec 2020, 19:16 last edited by
    #6

    And you added the server.cpp to your pro-file?

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    F 1 Reply Last reply 17 Dec 2020, 19:24
    0
    • C Christian Ehrlicher
      17 Dec 2020, 19:16

      And you added the server.cpp to your pro-file?

      F Offline
      F Offline
      fari35
      wrote on 17 Dec 2020, 19:24 last edited by
      #7

      @Christian-Ehrlicher yes, see I have added all the files:

      QT       += core
      QT       +=network
      QT       +=gui
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      CONFIG += c++11
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      TEMPLATE = app
      SOURCES += \
          main.cpp \
          mainwindow.cpp
          myserver.cpp
          mythread.cpp
      
      HEADERS += \
          mainwindow.h
          myserver.h
          mythread.h
      
      FORMS += \
          mainwindow.ui
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      
      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 17 Dec 2020, 19:31 last edited by
        #8

        @fari35 said in Multi threaded TCP server GUI using Qt widgets application:

        > SOURCES += \
        >     main.cpp \
        >     mainwindow.cpp
        >     myserver.cpp
        >     mythread.cpp
        

        This does not look correct - you forgot the \

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        F 1 Reply Last reply 17 Dec 2020, 19:34
        4
        • C Christian Ehrlicher
          17 Dec 2020, 19:31

          @fari35 said in Multi threaded TCP server GUI using Qt widgets application:

          > SOURCES += \
          >     main.cpp \
          >     mainwindow.cpp
          >     myserver.cpp
          >     mythread.cpp
          

          This does not look correct - you forgot the \

          F Offline
          F Offline
          fari35
          wrote on 17 Dec 2020, 19:34 last edited by fari35
          #9

          @Christian-Ehrlicher Do I need to put this \ in front of every file?

          J 1 Reply Last reply 17 Dec 2020, 19:35
          0
          • F fari35
            17 Dec 2020, 19:34

            @Christian-Ehrlicher Do I need to put this \ in front of every file?

            J Offline
            J Offline
            JonB
            wrote on 17 Dec 2020, 19:35 last edited by
            #10

            @fari35
            No, it's a line continuation character. It must go at the end of each line in a list of file names other than the final one.

            F 1 Reply Last reply 17 Dec 2020, 19:44
            4
            • J JonB
              17 Dec 2020, 19:35

              @fari35
              No, it's a line continuation character. It must go at the end of each line in a list of file names other than the final one.

              F Offline
              F Offline
              fari35
              wrote on 17 Dec 2020, 19:44 last edited by
              #11

              @JonB I have checked that but still I'm getting the same error. I have added all the files with their code in my question. Can you please tell me what I'm doing wrong here?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 17 Dec 2020, 19:53 last edited by
                #12

                Please post your pro file and start over with a clean build dir

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                F 1 Reply Last reply 17 Dec 2020, 19:55
                2
                • C Christian Ehrlicher
                  17 Dec 2020, 19:53

                  Please post your pro file and start over with a clean build dir

                  F Offline
                  F Offline
                  fari35
                  wrote on 17 Dec 2020, 19:55 last edited by
                  #13

                  @Christian-Ehrlicher This is my pro file:

                  QT       += core
                  QT       +=network
                  QT       +=gui
                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                  
                  CONFIG += c++11
                  
                  # You can make your code fail to compile if it uses deprecated APIs.
                  # In order to do so, uncomment the following line.
                  #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                  TEMPLATE = app
                  SOURCES += \
                      main.cpp \
                      mainwindow.cpp\
                      myserver.cpp
                      mythread.cpp
                  
                  HEADERS += \
                      mainwindow.h\
                      myserver.h
                      mythread.h
                  
                  FORMS += \
                      mainwindow.ui
                  
                  # Default rules for deployment.
                  qnx: target.path = /tmp/$${TARGET}/bin
                  else: unix:!android: target.path = /opt/$${TARGET}/bin
                  !isEmpty(target.path): INSTALLS += target
                  
                  
                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 17 Dec 2020, 19:56 last edited by
                    #14

                    You did notice what @JonB and I told you? You forgot to add the \ ...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    F 1 Reply Last reply 18 Dec 2020, 11:44
                    1
                    • C Christian Ehrlicher
                      17 Dec 2020, 19:56

                      You did notice what @JonB and I told you? You forgot to add the \ ...

                      F Offline
                      F Offline
                      fari35
                      wrote on 18 Dec 2020, 11:44 last edited by fari35
                      #15

                      @Christian-Ehrlicher @JonB yes Now its working but when I'm trying to create an object of MainWindow class in server.h class so I'm not able to create that. Cany you please tell me how can I make the object of MainWindow class?
                      server.h:

                      #ifndef SERVER_H
                      #define SERVER_H
                      #include <QStringList>
                      #include <QTcpServer>
                      #include "mainwindow.h"
                      class server : public QTcpServer
                      {
                          Q_OBJECT
                      
                      public:
                          server(QObject *parent = nullptr);
                          QTcpServer *tcpServer;
                          
                      protected:
                          void incomingConnection(qintptr socketDescriptor) override;
                      
                      private:
                          QStringList fortunes;
                          MainWindow uicopy;
                          
                      };
                      #endif // SERVER_H
                      
                      
                      J 1 Reply Last reply 18 Dec 2020, 11:59
                      0
                      • F fari35
                        18 Dec 2020, 11:44

                        @Christian-Ehrlicher @JonB yes Now its working but when I'm trying to create an object of MainWindow class in server.h class so I'm not able to create that. Cany you please tell me how can I make the object of MainWindow class?
                        server.h:

                        #ifndef SERVER_H
                        #define SERVER_H
                        #include <QStringList>
                        #include <QTcpServer>
                        #include "mainwindow.h"
                        class server : public QTcpServer
                        {
                            Q_OBJECT
                        
                        public:
                            server(QObject *parent = nullptr);
                            QTcpServer *tcpServer;
                            
                        protected:
                            void incomingConnection(qintptr socketDescriptor) override;
                        
                        private:
                            QStringList fortunes;
                            MainWindow uicopy;
                            
                        };
                        #endif // SERVER_H
                        
                        
                        J Offline
                        J Offline
                        JonB
                        wrote on 18 Dec 2020, 11:59 last edited by
                        #16

                        @fari35
                        You make a MainWindow object/instance by MainWindow instance or MainWindow *istance = new MainWindow.

                        when I'm trying to create an object of MainWindow class in server.h class

                        You absolutely do not want to create, or reference, any MainWindow class/object, or for that matter any UI object, in your server.h/.cpp files, which should solely work on QTcp... stuff! And nor should it attempt to #include "mainwindow.h"....

                        You need to learn to keep your classes separate, each one only doing what it needs for its own specialized functionality.

                        If, say, you do have a QMainWindow in an application using QTcpServer, mainwindow can know about server, but not the other way round. MainWindow can call methods in QTcpServer, but not the other way round. Or, they can use signals/slots if required to communicate.

                        1 Reply Last reply
                        4

                        15/16

                        18 Dec 2020, 11:44

                        • Login

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