diff --git a/hit2023v2/eventbuilder.cpp b/hit2023v2/eventbuilder.cpp index 4cb0679..212183c 100644 --- a/hit2023v2/eventbuilder.cpp +++ b/hit2023v2/eventbuilder.cpp @@ -1,5 +1,5 @@ #include "eventbuilder.h" -#include "udpserver.h" // Include the UDP server header +#include "udpserver.h" EventBuilder::EventBuilder(QObject *parent) : QObject(parent) { @@ -10,9 +10,6 @@ EventBuilder::EventBuilder(QObject *parent) : QObject(parent) connect(this, EventBuilder::sigStartTakingHistos, this, EventBuilder::onStartTakingHistos); connect(this, EventBuilder::sigStopTakingHistos, this, EventBuilder::onStopTakingHistos); - // Create an instance of your UDP server class - udpServer = new UdpServer(this); - moveToThread(&thread); thread.start(); init(); @@ -88,7 +85,7 @@ void EventBuilder::onNewData(DataReceiver* receiver) // Call sendData method of the UDP server QString dataString = QString::number(intensity) + ',' + QString::number(position) + ',' + QString::number(focus); QByteArray data = dataString.toUtf8(); - udpServer->sendData(data); + udpServer.sendData(data); } diff --git a/hit2023v2/eventbuilder.h b/hit2023v2/eventbuilder.h index 2b25564..f4567c0 100644 --- a/hit2023v2/eventbuilder.h +++ b/hit2023v2/eventbuilder.h @@ -88,7 +88,6 @@ protected slots: void onStartTakingHistos(int sample_count); void onStopTakingHistos(); private: - UdpServer* udpServer; // Declare a member variable for the UDP server double intensity = 0.0; double position = 0.0; double focus = 0.0; diff --git a/hit2023v2/main.cpp b/hit2023v2/main.cpp index 213a76d..9db49a4 100644 --- a/hit2023v2/main.cpp +++ b/hit2023v2/main.cpp @@ -1,11 +1,15 @@ #include "mainwindow.h" #include #include "udpserver.h" // Include udpserver header + +// Define the global UdpServer object +UdpServer udpServer; // This allocates memory for udpServer + int main(int argc, char *argv[]) { QApplication a(argc, argv); - // Create and start the UDP server - UdpServer udpServer; // Assuming your UdpServer class is properly defined + + // Create the UdpServer object on the heap and store a pointer to it udpServer.startServer(); // Apply the stylesheet to each display diff --git a/hit2023v2/release/hit2023v2.exe b/hit2023v2/release/hit2023v2.exe index 79a7d66..45b13f8 100644 Binary files a/hit2023v2/release/hit2023v2.exe and b/hit2023v2/release/hit2023v2.exe differ diff --git a/hit2023v2/udpserver.h b/hit2023v2/udpserver.h index ccf5853..16e05c0 100644 --- a/hit2023v2/udpserver.h +++ b/hit2023v2/udpserver.h @@ -5,6 +5,8 @@ #include #include // Add this line to include QTimer + + class UdpServer : public QObject { Q_OBJECT @@ -23,4 +25,7 @@ private: }; +// Declare the global UdpServer object as an external variable +extern UdpServer udpServer; + #endif // UDPSERVER_H