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. QDBusConnection: systerm Dbus connection created before QCoreApplication
Forum Update on Monday, May 27th 2025

QDBusConnection: systerm Dbus connection created before QCoreApplication

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 5 Posters 4.3k 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.
  • aha_1980A aha_1980

    @mrjj is fully right, defining the Non-Plain-Old-Data objects in the CPP file as global variables is dangerous.

    They may as well be used before they are constructed which will crash your program!

    This applies to all the following variables:

    QNetworkConfigurationManager ncm1;
    QStringList WiFisList;
    QList<QNetworkConfiguration> netcfgList;
    QString server_rx_data;

    You should put them as member variables into your class, and while at it, you can put the int variables there also.

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

    @aha_1980

    AFAIK, QString, QStringList and QList are not concerned as they have no dependencies on Qt's internal state. That said, I agree that all of these should be handled by the proper class.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    aha_1980A 1 Reply Last reply
    0
    • A Offline
      A Offline
      Anny
      wrote on last edited by
      #9

      @mrjj @aha_1980 @SGaist Thank you, Ill define these as member variables and will get back to you.

      1 Reply Last reply
      0
      • SGaistS SGaist

        @aha_1980

        AFAIK, QString, QStringList and QList are not concerned as they have no dependencies on Qt's internal state. That said, I agree that all of these should be handled by the proper class.

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #10

        @SGaist said in QDBusConnection: systerm Dbus connection created before QCoreApplication:

        @aha_1980

        AFAIK, QString, QStringList and QList are not concerned as they have no dependencies on Qt's internal state.

        they don't contribute to the current problem, but may create other problems later.

        That said, I agree that all of these should be handled by the proper class.

        @Anny the reason is, that objects need to be constructed before usage. as a global variable, the time when their constructor runs is undefined. so it is possible, that you access variables before construction, which can even lead to crashes.

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Anny
          wrote on last edited by Anny
          #11

          Hi @aha_1980 as you said I just declared objects just before usage ,this error is gone . I also tried defining these objects in the header file of class ,there is no error.
          Edit: now there is no such warning/error but this code is not giving me status of wifi connection.I mean it should update status every 5 sec, but it just shows status of wifi in the very first iteration.
          I have a doubt I don't know If I can ask in the same thread, I have defined various variables,strings,structures in global.h file as external and I call them in different files. will this crash my application ?

          jsulmJ 1 Reply Last reply
          0
          • A Anny

            Hi @aha_1980 as you said I just declared objects just before usage ,this error is gone . I also tried defining these objects in the header file of class ,there is no error.
            Edit: now there is no such warning/error but this code is not giving me status of wifi connection.I mean it should update status every 5 sec, but it just shows status of wifi in the very first iteration.
            I have a doubt I don't know If I can ask in the same thread, I have defined various variables,strings,structures in global.h file as external and I call them in different files. will this crash my application ?

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

            @Anny Your

            while(true)
            

            loop is blocking Qt event loop. Remove it and use the asynchronous nature of Qt (you can use QTimer firing in 5 seconds intervals).

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

            1 Reply Last reply
            2
            • A Offline
              A Offline
              Anny
              wrote on last edited by
              #13

              @jsulm yeah i tried using timer but it not working i dont know why. I m using Timer in other classes , there it works fine. So i switched to thread::sleep

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Anny
                wrote on last edited by
                #14

                @jsulm What I did is, I removed while(true) and sleep command and added timer
                connect(&check_network_timer,QTimer::timeout,this,&server_conneciton::run)
                check_network_timer.start(5000);
                This gives me nothing, app crashes after starting timer

                mrjjM 1 Reply Last reply
                0
                • A Anny

                  @jsulm What I did is, I removed while(true) and sleep command and added timer
                  connect(&check_network_timer,QTimer::timeout,this,&server_conneciton::run)
                  check_network_timer.start(5000);
                  This gives me nothing, app crashes after starting timer

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #15

                  @Anny
                  Hi
                  Where does it crash ?
                  You can use the debugger to see what is going on.
                  Using timer normally do not crash so there must be some error in the code.

                  1 Reply Last reply
                  1
                  • A Offline
                    A Offline
                    Anny
                    wrote on last edited by
                    #16

                    @mrjj I tried debugging it using debugger but it gives error box of segmentation fault saying signal received. what does it mean ?

                    mrjjM 1 Reply Last reply
                    0
                    • A Anny

                      @mrjj I tried debugging it using debugger but it gives error box of segmentation fault saying signal received. what does it mean ?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #17

                      @Anny
                      Hi
                      It sounds like its crashing. ( segmentation faults = bad pointers, memory issues etc)
                      Place break point at top of function that timer calls etc and see if it stops.

                      1 Reply Last reply
                      1
                      • A Offline
                        A Offline
                        Anny
                        wrote on last edited by Anny
                        #18

                        @mrjj I added break points it does not stop. But when I run this class as QThread, app didnt crash but stuck after starting timer. I used moveToThread method to run it as thread. I also checked debugger and added some breakpoints, still not stopping and giving same segmentation fault. There is something I am missing out,I dont know what

                        mrjjM 1 Reply Last reply
                        0
                        • A Anny

                          @mrjj I added break points it does not stop. But when I run this class as QThread, app didnt crash but stuck after starting timer. I used moveToThread method to run it as thread. I also checked debugger and added some breakpoints, still not stopping and giving same segmentation fault. There is something I am missing out,I dont know what

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #19

                          @Anny

                          Hi
                          Do you start it with debug and not just normal run ?
                          It should stop.

                          1 Reply Last reply
                          2
                          • A Offline
                            A Offline
                            Anny
                            wrote on last edited by Anny
                            #20

                            @mrjj yeah i did it using debug mode. But I got this working now, there was some QThread related issue. Thank you so much everyone

                            1 Reply Last reply
                            2

                            • Login

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