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. Network Status.
Forum Update on Monday, May 27th 2025

Network Status.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.1k 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.
  • M Offline
    M Offline
    MyQT
    wrote on last edited by
    #1

    Hi,

    I am using below code to check whether the network of my machine is up or not.
    If network is up and running then I am trying to connect the TCP socket.

    @
    QList<QNetworkInterface> tempList = ni.allInterfaces();
    int status = ((tempList[0].flags()) & QNetworkInterface::IsUp);
    if(status)
    {
    tcp_.connectToHost(QHostAddress(gpsRecIPAddr_), portNumber_);
    }
    @

    Above code was wooking fine.
    I was getting below newtwork status,
    QFlags(0x1|0x2|0x4|0x20)

    But when we connected wirless network(Netgear) to my PC then bove code started giving problem.

    In above code, "status" variable did not turn true. So TCP connection was failed.
    Also i was getting below network flags,
    QFlags(0x4|0x20) -- (Here network flags status which is output of allInterfaces function, is also changed as compered previous one)

    Just wanted to know why TCP connecion was not happning through above code?. I removed netgear wireless connection and its divers but getting same issue TCP connection failure.

    Any help will be helpful.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      That code is a bit stupid...

      First you grab a list of interfaces and then check that the first one is up and ignore whether any other is up. So if the first one is down (e.g. your built-in ethernet without a wire in it) but there are 20 others that are up (e.g. a wireless card), then you do not even try to connect.

      If there is no network interface at all, then you crash.

      If there is no interface up the connectToHost should fail instantly, so you do not gain anything by the IsUp test.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MyQT
        wrote on last edited by
        #3

        Hi, Thanks for the reply.

        Here my pupose is, I want to check that LAN cable is connected propely to my PC first then only trying to connect the TCP.
        Is there any other better way to check that?

        Thansk in advance.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          Tobias Hunger said, after you got the list of Network Interfaces, don't blindly access the first one (index #0), as the list might be empty and you could easily get a crash there! So first step would be to check if the number of network interfaces is greater than zero. If not, then you don't have a network interface and thus you obviously don't have a connection. If there is a network interface in the list (maybe several!), don't just check the first one. Instead, check all of them in a loop. What you want probably is at least one interface that "is up".

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            Do you really have a guarantee that @tempList[0]@ is really your physical ethernet port?

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            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