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
QtWS25 Last Chance

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.
  • M4RZB4NiM Offline
    M4RZB4NiM Offline
    M4RZB4Ni
    wrote on 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      do you have

      uSocket = new QUdpSocket(this) ;

      anywhere?

      M4RZB4NiM 1 Reply Last reply
      2
      • mrjjM mrjj

        hi
        do you have

        uSocket = new QUdpSocket(this) ;

        anywhere?

        M4RZB4NiM Offline
        M4RZB4NiM Offline
        M4RZB4Ni
        wrote on last edited by
        #3

        @mrjj
        hi
        no! i dont this
        why??

        Thanks
        M4RZB4Ni

        mrjjM 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          • M4RZB4NiM Offline
            M4RZB4NiM Offline
            M4RZB4Ni
            wrote on 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
            • M4RZB4NiM M4RZB4Ni

              @mrjj
              hi
              no! i dont this
              why??

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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

              • Login

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