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. Appending QStringList crashes
Forum Updated to NodeBB v4.3 + New Features

Appending QStringList crashes

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 3.0k 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.
  • H Hubbard

    In fact it seems to crash using 'mac' for anything at all outside of using it to initialize a class and output it through qDebug() once, Its hard for me to show the code as it is on a different platform.

    O Offline
    O Offline
    ollarch
    wrote on last edited by
    #5

    @Hubbard Use the debugger. Maybe you are using an invalid pointer.

    H 1 Reply Last reply
    2
    • H Hubbard

      In fact it seems to crash using 'mac' for anything at all outside of using it to initialize a class and output it through qDebug() once, Its hard for me to show the code as it is on a different platform.

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

      @Hubbard Well, then I have no idea.
      You should at least try to debug your app. Most probably the pointer is invalid at the time the app is crashing. What type of crash is it actually (SIGSEGV, ...)?

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

      1 Reply Last reply
      2
      • O ollarch

        @Hubbard Use the debugger. Maybe you are using an invalid pointer.

        H Offline
        H Offline
        Hubbard
        wrote on last edited by
        #7

        @ollarch You're right...

        none of it is the problem apart from trying to use ownedMacAddresses
        just

        qDebug() << ownedMacAddresses[0];

        in the slot

        crashes the program

        jsulmJ 1 Reply Last reply
        0
        • H Hubbard

          I have a large program which does many things at once (including multiple threads)

          and a small addition to a particular part of my code crashes it, in the mainWindow class a pointer QStringList exists that stores a set of mac addresses, this QStringList is initialised initially with ownedMacAddresses = &tempStringList, and later on in the code prompted by the user a mac address can be found and passed by way of signal to a slot which processes it, which is fine (QString mac is passed through the connection), however, when I try to ownedMacAddresses->append(mac), it crashes when the user clicks the button at this point, why?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #8

          @Hubbard said in Appending QStringList crashes:

          &tempStringList

          Has tempStringList gone out of scope?

          H 1 Reply Last reply
          1
          • JonBJ JonB

            @Hubbard said in Appending QStringList crashes:

            &tempStringList

            Has tempStringList gone out of scope?

            H Offline
            H Offline
            Hubbard
            wrote on last edited by
            #9

            @JonB No but when I qDebug() << it from somewhere else it doesn't crash but outputs the element in brackets

            ("2C:3A:E8:37:D8:6A") as opposed to "2C:3A:E8:37:D8:6A"

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hubbard
              wrote on last edited by
              #10

              Never ->at(0) instead fixes that

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hubbard
                wrote on last edited by
                #11

                Still crashes inside the slot

                qDebug() << ownedMacAddresses->at(0);

                anywhere else in mainWindow is fine, in this slot, nah

                1 Reply Last reply
                0
                • H Hubbard

                  @ollarch You're right...

                  none of it is the problem apart from trying to use ownedMacAddresses
                  just

                  qDebug() << ownedMacAddresses[0];

                  in the slot

                  crashes the program

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

                  @Hubbard said in Appending QStringList crashes:

                  qDebug() << ownedMacAddresses[0];

                  This can't work the way you expect it to work, because ownedMacAddresses is a pointer. If you want to do it this way then so:

                  qDebug() << (*ownedMacAddresses)[0];
                  

                  "Still crashes inside the slot
                  qDebug() << ownedMacAddresses->at(0);" - did you try to place a breakpoint at that line and see whether ownedMacAddresses is a valid pointer? Also - what kind of crash is it (SIGSEGV?)?

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

                  1 Reply Last reply
                  1
                  • H Offline
                    H Offline
                    Hubbard
                    wrote on last edited by
                    #13

                    What do you mean by 'valid pointer'?

                    jsulmJ 1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hubbard
                      wrote on last edited by
                      #14

                      If its related I have begun to pass the pointer through the signal

                      now the crash error gives me an 'index out of range' error at element 0, implying something is definitely not right with the pointer to the array

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        Hubbard
                        wrote on last edited by
                        #15

                        Like 'emit signal(..., QStringList* currentMacs);'

                        1 Reply Last reply
                        0
                        • H Hubbard

                          What do you mean by 'valid pointer'?

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

                          @Hubbard Mit "valid pointer" I mean a pointer pointing to reserved memory and not to nirvana.

                          QStringList* p1; // Invalid pointer
                          QStringList* p2 = new QStringList(); // Valid pointer
                          

                          "Index out of range at element 0" means that you do not have any elements in the list. Check that with:

                          qDebug() << currentMacs->size();
                          

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

                          1 Reply Last reply
                          1
                          • H Offline
                            H Offline
                            Hubbard
                            wrote on last edited by
                            #17

                            I see now

                            QStringList declared in the header file makes a tonne more sense and works better than QStringList*.

                            Thinking about it QStringList and arrays and things come with their own addresses anyway.

                            Thank you guys

                            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