Solved How to stop writeDatagram ?
-
You should debug your infinite loop. As long as you have
Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A
returning true then you'll have datagram sent.On a side note, you might be interested by the QtGamePad module.
-
@BadHombre said in How to stop writeDatagram ?:
CXBOXController
Is that from here ?
https://www.codeproject.com/Articles/26949/Xbox-Controller-Input-in-C-with-XInputThat is close to 10 years old :)
Are you sure
Player1->GetState().Gamepad.wButtons returns the actual state and not just
the value for some other field ?
I would put in a
std::cout << "GetState: =" << (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A);
and check it actually still works. -
i debuged it now and the gamepad control works so it jumps into the if clause of A and then stops working at
udpSocket->writeDatagram(datagram.data(), datagram.size(),QHostAddress::Broadcast, 45454);
after clicking 3 time F10... but its strange because in the example it works fine
I am not using the QT Gamepad module because it seems that there is a bug ... it didn't recognize my gamepad :/
@mrjj yes that's the link :) -
hi
it stays inside udpSocket->writeDatagram or in what way stops working ?
The socket is new´ed and ready ? -
yes the socket is new ..
this is the header file :#ifndef SENDER_H #define SENDER_H #include <QWidget> class QDialogButtonBox; class QLabel; class QPushButton; class QTimer; class QUdpSocket; class Sender : public QWidget { Q_OBJECT public: Sender(QWidget *parent = 0); private slots: void startBroadcasting(); void broadcastDatagram(); private: QLabel *statusLabel; QPushButton *startButton; QPushButton *quitButton; QDialogButtonBox *buttonBox; QUdpSocket *udpSocket; QTimer *timer; int messageNo; }; #endif
a window pop up wir .exe doesn't work anymore
-
@BadHombre said in How to stop writeDatagram ?:
QUdpSocket *udpSocket;
and you have/do
udpSocket = new QUdpSocket ;
somewhere ? -
oh i forgot it :S it works now ...
sry ... stupid error -
@BadHombre
Ok, so it was a dangling pointer :)
Well its easy error to make.
Even pretty experienced i sometimes copy from .h file
like
QUdpSocket *udpSocket;
and do
QUdpSocket *udpSocket = new QUdpSocket ;
Which makes a new variable and do not new the one in .hso stupid error will always be made :)
-
Thank you :) One last question ... if i run it with the debugger it works fine ... so it enter only 1 time into the if clause and send it ... but if i run the program and click on a on the gamepad it enter sth like 30 times ... so it sends 30 commands... so it seems that its to fast when i start the program normal ... it's like i am pressing the button to long :S How could i fix that ? mybe with a time and an if ? or is there a better way ?
-
@BadHombre
It sounds like thread is too fast so that the XInput is not yet updated.
so this
if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
is true for 30 times before it sort of discovered that you are not holding the button?you could use a timer and let it call a function like the run()
(not while using run() for a thread of course)Then you can set the speed. (of the timer and hence how fast it calls)
There is also
QThread::msleep(1000);
to slow it down but timer is better design.
However for testing you can try that.