I'm developing a UI with Qt Creator that controls an OPC Server.
Check Input Function OPC Server:
void runUserInterface()
{
// we have an endless loop waiting for a keyboard input
bool end = false;
_tprintf(_T("The server is running.\n"));
usage();
while(!end)
{
// variables for input purposes
tstring input = _T("");
cin >> input;
if (input == _T("x") || input == _T("q") || input == _T("X") || input == _T("Q"))
{
// exit if one of the four exit characters is hit
_tprintf(_T("Shutdown\n"));
end = true;
}
if (input == _T("s"))
{
// exit if one of the four exit characters is hit
_tprintf(_T("Shutdown\n"));
end = true;
}
}
}
void runUserInterface()
{
// we have an endless loop waiting for a keyboard input
bool end = false;
_tprintf(_T("The server is running.\n"));
usage();
while(!end)
{
// variables for input purposes
tstring input = _T("");
cin >> input;
if (input == _T("x") || input == _T("q") || input == _T("X") || input == _T("Q"))
{
// exit if one of the four exit characters is hit
_tprintf(_T("Shutdown\n"));
end = true;
}
if (input == _T("s"))
{
// exit if one of the four exit characters is hit
_tprintf(_T("Shutdown\n"));
end = true;
}
}
}
To copy to clipboard, switch view to plain text mode
When I run it in Visual Studio, it's working and the Server shuts down. When I write to the Process in Qt Creator, the UI stops working.
Source Code from UI
#include "control_window.h"
#include "ui_control_window.h"
#include "configuration_window.h"
#include "configuration_window.cpp"
#include <QProcess>
#include <QWidget>
#define CMD_EXIT "q"
control_window
::control_window(QWidget *parent
) : ui(new Ui::control_window)
{
ui->setupUi(this);
}
control_window::~control_window()
{
delete ui;
}
void control_window::on_control_window_Exit_clicked()
{
m_opc_ua_server->write(CMD_EXIT);
m_opc_ua_server->waitForBytesWritten();
}
#include "control_window.h"
#include "ui_control_window.h"
#include "configuration_window.h"
#include "configuration_window.cpp"
#include <QProcess>
#include <QWidget>
#define CMD_EXIT "q"
control_window::control_window(QWidget *parent) :
QWidget(parent),
ui(new Ui::control_window)
{
ui->setupUi(this);
}
control_window::~control_window()
{
delete ui;
}
void control_window::on_control_window_Exit_clicked()
{
m_opc_ua_server->write(CMD_EXIT);
m_opc_ua_server->waitForBytesWritten();
}
To copy to clipboard, switch view to plain text mode
The UI just crashes when on_control_window_Exit_clicked() is triggered, the OPC Server is still running though.
It also crashes when I use m_opc_ua_server->terminate();
I think the problem is in the UI, I made a small test program and the same error occurs.
test program:
#include "stdafx.h"
#include <string>
#include <iostream>
class MyClass
{
public:
MyClass();
~MyClass();
void checkinput();
private:
};
MyClass::MyClass()
{
}
MyClass::~MyClass()
{
}
void MyClass::checkinput()
{
}
string input = "";
void checkinput()
{
cin >> input;
}
int main()
{
bool end = false;
while (!end)
{
checkinput();
if (input == "j")
{
end = true;
}
}
}
#include "stdafx.h"
#include <string>
#include <iostream>
class MyClass
{
public:
MyClass();
~MyClass();
void checkinput();
private:
};
MyClass::MyClass()
{
}
MyClass::~MyClass()
{
}
void MyClass::checkinput()
{
}
string input = "";
void checkinput()
{
cin >> input;
}
int main()
{
bool end = false;
while (!end)
{
checkinput();
if (input == "j")
{
end = true;
}
}
}
To copy to clipboard, switch view to plain text mode
What's wrong?
Bookmarks