UDPSocket Stopped Working
- 
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 fileQUdpSocket *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()); } }
- 
hi 
 do you haveuSocket = new QUdpSocket(this) ; anywhere? 
- 
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. 
- 
@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.
