跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  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

已排程 已置頂 已鎖定 已移動 Unsolved General and Desktop
23 貼文 7 Posters 4.3k 瀏覽
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • JonBJ JonB

    @RaptaG
    It provides all the (non-UI) services Qt requires/offers (signals, slots, lots & lots of other stuff, initializations)... basically a Qt program won;t work without one, else it's a not a program actually using Qt.

    R 離線
    R 離線
    RaptaG
    寫於 最後由 編輯
    #12

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

    JonBJ 1 條回覆 最後回覆
    0
    • R RaptaG

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

      JonBJ 離線
      JonBJ 離線
      JonB
      寫於 最後由 編輯
      #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 條回覆 最後回覆
      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 離線
        R 離線
        RaptaG
        寫於 最後由 編輯
        #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 條回覆 最後回覆
        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 離線
          jsulmJ 離線
          jsulm
          Lifetime Qt Champion
          寫於 最後由 編輯
          #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 條回覆 最後回覆
          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 離線
            R 離線
            RaptaG
            寫於 最後由 編輯
            #16

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

            JonBJ 1 條回覆 最後回覆
            0
            • R RaptaG

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

              JonBJ 離線
              JonBJ 離線
              JonB
              寫於 最後由 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 條回覆 最後回覆
              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 離線
                R 離線
                RaptaG
                寫於 最後由 編輯
                #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 條回覆 最後回覆
                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 離線
                  jsulmJ 離線
                  jsulm
                  Lifetime Qt Champion
                  寫於 最後由 編輯
                  #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 條回覆 最後回覆
                  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 離線
                    R 離線
                    RaptaG
                    寫於 最後由 編輯
                    #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 條回覆 最後回覆
                    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 離線
                      jsulmJ 離線
                      jsulm
                      Lifetime Qt Champion
                      寫於 最後由 編輯
                      #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 條回覆 最後回覆
                      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 離線
                        R 離線
                        RaptaG
                        寫於 最後由 編輯
                        #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 條回覆 最後回覆
                        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 離線
                          jsulmJ 離線
                          jsulm
                          Lifetime Qt Champion
                          寫於 最後由 編輯
                          #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 條回覆 最後回覆
                          1

                          • 登入

                          • Login or register to search.
                          • 第一個貼文
                            最後的貼文
                          0
                          • 版面
                          • 最新
                          • 標籤
                          • 熱門
                          • 使用者
                          • 群組
                          • 搜尋
                          • Get Qt Extensions
                          • Unsolved