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. Checking if a device has an active internet connection
Forum Updated to NodeBB v4.3 + New Features

Checking if a device has an active internet connection

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 7 Posters 4.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.
  • R RaptaG

    @JonB Can I borrow your code and use it on my open-source project (GPL3)? I will credit you.

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #13

    @RaptaG
    I don't know what code you are thinking of and not sure what you could want? But you are welcome to whatever, no credit necessary.

    R 1 Reply Last reply
    0
    • JonBJ JonB

      @RaptaG
      I don't know what code you are thinking of and not sure what you could want? But you are welcome to whatever, no credit necessary.

      R Offline
      R Offline
      RaptaG
      wrote on last edited by
      #14

      @JonB

      Something else now, if I use it in a bool function, then return a.exec() is not necessary, right?

      Also, how likely is it for the first 2 if statements not to be the case?

      jsulmJ 1 Reply Last reply
      0
      • R RaptaG

        @JonB

        Something else now, if I use it in a bool function, then return a.exec() is not necessary, right?

        Also, how likely is it for the first 2 if statements not to be the case?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #15

        @RaptaG said in Checking if a device has an active internet connection:

        return a.exec() is not necessary, right?

        Wrong.
        If you're writing a Qt application which requires the event loop to be running (most Qt applications) then you have to call exec()...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        R 1 Reply Last reply
        0
        • jsulmJ jsulm

          @RaptaG said in Checking if a device has an active internet connection:

          return a.exec() is not necessary, right?

          Wrong.
          If you're writing a Qt application which requires the event loop to be running (most Qt applications) then you have to call exec()...

          R Offline
          R Offline
          RaptaG
          wrote on last edited by
          #16

          @jsulm so, how do i adjust it so that it works in a bool function?

          JonBJ 1 Reply Last reply
          0
          • R RaptaG

            @jsulm so, how do i adjust it so that it works in a bool function?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #17

            @RaptaG
            I really don't think we know what you are asking about here.

            There is nothing to stop you calling exec() in a function, boolean or not.

            bool foo()
            {
                int unusedReturnResult = someApplicationObject.exec();
                // ignore that return result
                return false;    // whatever boolean value you want
            }
            

            However, since exec() is the entry point to running the main Qt application event loop you are only going to want to call it once (and it does not exit till Qt quits event loop). So I cannot imagine what/why you want to move it to some function which returns a boolean. Makes me thing you are going to use it oddly. If you are thinking of calling this each time you want to check "if a device has an active internet connection" this is not the architecture.

            R 1 Reply Last reply
            1
            • JonBJ JonB

              @RaptaG
              I really don't think we know what you are asking about here.

              There is nothing to stop you calling exec() in a function, boolean or not.

              bool foo()
              {
                  int unusedReturnResult = someApplicationObject.exec();
                  // ignore that return result
                  return false;    // whatever boolean value you want
              }
              

              However, since exec() is the entry point to running the main Qt application event loop you are only going to want to call it once (and it does not exit till Qt quits event loop). So I cannot imagine what/why you want to move it to some function which returns a boolean. Makes me thing you are going to use it oddly. If you are thinking of calling this each time you want to check "if a device has an active internet connection" this is not the architecture.

              R Offline
              R Offline
              RaptaG
              wrote on last edited by
              #18

              @JonB said in Checking if a device has an active internet connection:

              If you are thinking of calling this each time you want to check "if a device has an active internet connection"

              That's what I was planning to do tbh 😅

              jsulmJ 1 Reply Last reply
              0
              • R RaptaG

                @JonB said in Checking if a device has an active internet connection:

                If you are thinking of calling this each time you want to check "if a device has an active internet connection"

                That's what I was planning to do tbh 😅

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #19

                @RaptaG said in Checking if a device has an active internet connection:

                That's what I was planning to do tbh

                Why? You will block your application. Qt is an asynchronous framework - you should use it as such. QTcpSocket is also asynchronous...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @RaptaG said in Checking if a device has an active internet connection:

                  That's what I was planning to do tbh

                  Why? You will block your application. Qt is an asynchronous framework - you should use it as such. QTcpSocket is also asynchronous...

                  R Offline
                  R Offline
                  RaptaG
                  wrote on last edited by
                  #20

                  @jsulm I am a newbie and async stuff look really difficult. Even then, I only need to check for internet connection very few times/day in my program

                  jsulmJ 1 Reply Last reply
                  0
                  • R RaptaG

                    @jsulm I am a newbie and async stuff look really difficult. Even then, I only need to check for internet connection very few times/day in my program

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #21

                    @RaptaG It is not that difficult and you should really learn it, else there is no point in using Qt.
                    QTcpSocket has a signal: https://doc.qt.io/qt-6/qabstractsocket.html#connected
                    Just connect a slot to it and if this slot is called you're connected.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    R 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @RaptaG It is not that difficult and you should really learn it, else there is no point in using Qt.
                      QTcpSocket has a signal: https://doc.qt.io/qt-6/qabstractsocket.html#connected
                      Just connect a slot to it and if this slot is called you're connected.

                      R Offline
                      R Offline
                      RaptaG
                      wrote on last edited by
                      #22

                      @jsulm I want to learn to use Qt properly, because I want to implement a GUI for my C++ project with it. Where eould suggest me to start learning Qt, considering I am a C++ beginner?

                      jsulmJ 1 Reply Last reply
                      0
                      • R RaptaG

                        @jsulm I want to learn to use Qt properly, because I want to implement a GUI for my C++ project with it. Where eould suggest me to start learning Qt, considering I am a C++ beginner?

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #23

                        @RaptaG You can start with the basic example applications https://doc.qt.io/qt-6/qtexamplesandtutorials.html

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1

                        • Login

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