Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. module "QtNetwork" is not installed

module "QtNetwork" is not installed

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    zeroalpha
    wrote on last edited by
    #1

    Hello. I am new to QML and am really loving it.

    I am trying to make a TCP client app with Qt 6.4.3 but I am getting an error: QML module not found (QtNetwork)

    qml module not found (QtNetwork)

    In QT Creator I did: Create Project>Application (Qt)>Qt Quick Application>qmake

    This is my qml code:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtNetwork
    
    Window {
        visible: true
        width: 400
        height: 300
        title: "TCP Client"
    
        property string host: "localhost"
        property int port: 1234
    
        TextField {
            id: messageField
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            width: parent.width * 0.8
            placeholderText: "Enter message"
            onTextChanged: sendButton.enabled = text.trim().length > 0
        }
    
        Button {
            id: sendButton
            anchors.top: messageField.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            text: "Send"
            enabled: false
            onClicked: {
                var socket = new QTcpSocket();
                socket.connectToHost(host, port);
                if (socket.state === QTcpSocket.ConnectedState) {
                    var message = messageField.text.trim();
                    socket.write(message);
                    socket.flush();
                    socket.disconnectFromHost();
                    messageField.text = "";
                } else {
                    console.log("Failed to connect to " + host + ":" + port);
                }
            }
        }
    }
    

    and this is my .pro file code:

    QT += quick network
    
    SOURCES += \
            main.cpp
    
    resources.files = main.qml 
    resources.prefix = /$${TARGET}
    RESOURCES += resources
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    Where is Qt Network? In the maintenance tool, I can't see Qt Network. Is it a seperate install like qt multimedia?

    SGaistS 1 Reply Last reply
    0
    • Z zeroalpha

      Hello. I am new to QML and am really loving it.

      I am trying to make a TCP client app with Qt 6.4.3 but I am getting an error: QML module not found (QtNetwork)

      qml module not found (QtNetwork)

      In QT Creator I did: Create Project>Application (Qt)>Qt Quick Application>qmake

      This is my qml code:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtNetwork
      
      Window {
          visible: true
          width: 400
          height: 300
          title: "TCP Client"
      
          property string host: "localhost"
          property int port: 1234
      
          TextField {
              id: messageField
              anchors.top: parent.top
              anchors.horizontalCenter: parent.horizontalCenter
              width: parent.width * 0.8
              placeholderText: "Enter message"
              onTextChanged: sendButton.enabled = text.trim().length > 0
          }
      
          Button {
              id: sendButton
              anchors.top: messageField.bottom
              anchors.horizontalCenter: parent.horizontalCenter
              text: "Send"
              enabled: false
              onClicked: {
                  var socket = new QTcpSocket();
                  socket.connectToHost(host, port);
                  if (socket.state === QTcpSocket.ConnectedState) {
                      var message = messageField.text.trim();
                      socket.write(message);
                      socket.flush();
                      socket.disconnectFromHost();
                      messageField.text = "";
                  } else {
                      console.log("Failed to connect to " + host + ":" + port);
                  }
              }
          }
      }
      

      and this is my .pro file code:

      QT += quick network
      
      SOURCES += \
              main.cpp
      
      resources.files = main.qml 
      resources.prefix = /$${TARGET}
      RESOURCES += resources
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      

      Where is Qt Network? In the maintenance tool, I can't see Qt Network. Is it a seperate install like qt multimedia?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Use the JavaScript network API. To the best of my knowledge, the Qt Network module is not exposed to QtQuick.

      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
      0
      • Z Offline
        Z Offline
        zeroalpha
        wrote on last edited by
        #3

        ok figured it out. Here is the working .pro file:

        QT += quick quickcontrols2 network
        
        CONFIG += c++11
        
        SOURCES += main.cpp
        
        RESOURCES += qml.qrc
        
        QML_IMPORT_PATH = $$PWD
        
        QML_DESIGNER_IMPORT_PATH = $$QML_IMPORT_PATH
        
        QQmlApplicationEngine {
            qmlProtectModule("Qt.Network", 1);
        }
        
        # Additional compiler flags (if any)
        QMAKE_CXXFLAGS += -Wall
        
        # Additional linker flags (if any)
        QMAKE_LFLAGS +=
        
        # Additional libraries (if any)
        LIBS +=
        

        This .pro file specifies that the project requires the QtQuick, QtQuickControls2, and QtNetwork modules, and sets the C++ version to c++11. The main.cpp file is listed as the project source file, and the qml.qrc file is listed as a project resource file.

        The QML_IMPORT_PATH and QML_DESIGNER_IMPORT_PATH variables are set to the current working directory, and the QQmlApplicationEngine line adds a module import statement for the Qt.Network module to avoid a QML import error.

        1 Reply Last reply
        0

        • Login

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