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. UDPSocket Stopped Working
Forum Update on Monday, May 27th 2025

UDPSocket Stopped Working

Scheduled Pinned Locked Moved Unsolved General and Desktop
networkudperror
6 Posts 3 Posters 1.9k 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
    M4RZB4Ni
    wrote on 30 Jul 2016, 20:28 last edited by
    #1

    Hello
    I Want To Save state of a combobox in Char variable and send The Amount of this variable
    by UdpSocket to Client and when Client Received Amount of variable Disable or Enable Some Objects
    I Wrote a Code For Doing This But When i Run This Code Show me Stopped Working Messsage!
    SomeBody Can Help me Please?
    .h file

        QUdpSocket *uSocket;
    
    

    .cpp file

    QSettings priSettings("Mobtakeran Fanavri KabooK","Kabook Physiothrapy");
    management_menu::management_menu(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::management_menu)
    {
     ui->setupUi(this);
    primessionOfNewUser();
    
    }
    
    void management_menu::primessionOfNewUser()
    {
        char priChkNuser;
        QByteArray *priPackNuser;
        if(ui->chkNewUser->currentIndex()==0)
        {
           priChkNuser='y';
           priPackNuser->append(priChkNuser);
           uSocket->writeDatagram(priPackNuser->data(),priPackNuser->size(),QHostAddress::Broadcast,45454);
           priSettings.setValue("PNU",ui->chkNewUser->currentIndex());
        }else if(ui->chkNewUser->currentIndex()==1){
            priChkNuser='n';
            priPackNuser->append(priChkNuser);
            uSocket->writeDatagram(priPackNuser->data(),priPackNuser->size(),QHostAddress::Broadcast,45454);
            priSettings.setValue("PNU",ui->chkNewUser->currentIndex());
    
        }
    
    }
    

    Thanks
    M4RZB4Ni

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 30 Jul 2016, 22:08 last edited by
      #2

      hi
      do you have

      uSocket = new QUdpSocket(this) ;

      anywhere?

      M 1 Reply Last reply 30 Jul 2016, 22:15
      2
      • M mrjj
        30 Jul 2016, 22:08

        hi
        do you have

        uSocket = new QUdpSocket(this) ;

        anywhere?

        M Offline
        M Offline
        M4RZB4Ni
        wrote on 30 Jul 2016, 22:15 last edited by
        #3

        @mrjj
        hi
        no! i dont this
        why??

        Thanks
        M4RZB4Ni

        M 1 Reply Last reply 31 Jul 2016, 07:57
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 30 Jul 2016, 22:46 last edited by
          #4

          Hi,

          You're not allocating priPackNuser so you're using an invalid pointer.

          In any case, there's no need to allocate priPackNuser on the heap. You should keep it on the stack.

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

          1 Reply Last reply
          2
          • M Offline
            M Offline
            M4RZB4Ni
            wrote on 31 Jul 2016, 06:26 last edited by
            #5

            hi
            thank you so much
            can you
            explain more and
            Correction my code please?

            i have abut 10 more function like this and if you correction this I would be grateful.

            Thanks
            M4RZB4Ni

            1 Reply Last reply
            0
            • M M4RZB4Ni
              30 Jul 2016, 22:15

              @mrjj
              hi
              no! i dont this
              why??

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 31 Jul 2016, 07:57 last edited by mrjj
              #6

              @M4RZB4Ni said:

              Hi
              When you dont have
              uSocket = new QUdpSocket(this) ;
              then
              uSocket->writeDatagram(xx
              will crash.
              as uSocket just point to random location. (dangling pointer)

              Next:
              QByteArray *priPackNuser; <<< also just a pointer.
              You should do ( as @SGaist mention)
              QByteArray priPackNuser;
              ( no *, means its real bytearray, not a pointer to one)
              So you change it from heap allocation to stack allocation.

              If you dont change to non pointer then you need
              QByteArray *priPackNuser = new QByteArray ;
              as else its a dangling pointer too!
              But no need for pointer to QByteArray here.

              1 Reply Last reply
              3

              5/6

              31 Jul 2016, 06:26

              • Login

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