Beckhoff Ads C++ Notification Callback - Qt Widget Label aktualisieren

Alles rund um die Programmierung mit Qt
Antworten
zwuebbl
Beiträge: 1
Registriert: 14. März 2023 06:40

Beckhoff Ads C++ Notification Callback - Qt Widget Label aktualisieren

Beitrag von zwuebbl »

Sehr geehrte Damen und Herren,
das Beckhoff infosys Beispiel läuft in der Konsole oder mit Debug Ausgaben einwandfrei.
Leider bekomme ich mein Gui Label nicht aktualisiert und das Programm stürzt ab.
Ich bin Relativ neu in Qt. Vielleicht kann mir hier jemand helfen. Im SPS Forum hatte ich leider bisher keinen Erfolg.

Im Anhang der Quellcode und im Verlauf das Kernproblem:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
labelNotification = new QLabel(this);

//connect(this, SIGNAL(clicked()), this, SLOT(click()));

CreateAdsNotification();


connect(this, SIGNAL(&callback(AdsNotificationHeader*)), this->labelNotification, SLOT(UpdateUi(AdsNotificationHeader*)));
}

// Callback-function
void __stdcall MainWindow::Callback(AmsAddr* pAddr, AdsNotificationHeader* pNotification, ulong hUser)
{
int nIndex;
static ulong nCount = 0;


qDebug() << ++nCount << ". Call:\n";

// print (to screen)) the value of the variable
qDebug() << "Value: " << *(ulong *)pNotification->data << '\n';
qDebug() << "Notification: " << pNotification->hNotification << '\n';

emit UpdateUi(pNotification); // Signal senden

//labelNotification->setText("Test");


// Größe des Buffers in Byte
qDebug() << "SampleSize: " << pNotification->cbSampleSize << '\n';

// 32-Bit Variable (auch Zeiger), die beim AddNotification gesetzt wurde // (siehe main)
qDebug() << "hUser: " << hUser << '\n';

// Print out the ADS-address of the sender
qDebug()<< "ServerNetId: ";
for (nIndex = 0; nIndex < 6; nIndex++)
qDebug() << (int)pAddr->netId.b[nIndex] << ".";
qDebug() << "\nPort: " << pAddr->port << "\n\n";
//cout.flush();
}

void MainWindow::UpdateUi(AdsNotificationHeader* pNotification)
{
qDebug() << "Aufgerufen";

//labelNotification->setText(QString::number(*(ulong *)pNotification->data));
}

Mit freundlichen Grüßen

zwuebbl
Dateianhänge
QtAdsWidget (2).zip
(15.83 KiB) 350-mal heruntergeladen
Antworten