我的 BB 10 级联中有一个套接字连接应用程序,当套接字连接关闭时,我需要显示一个对话框,并且按下 OK 按钮应用程序需要关闭。
请在这里找到我的代码...
void SocketBase::writeLine(QTcpSocket *socket, const QString &line)
{
if (socket->state() != QAbstractSocket::ConnectedState)
{
onOkAlert("Please check your internet connection and restart the app again");
}
}
无效 SocketBase::onOkAlert(const QString &message) {
dialog = new SystemDialog(tr("OK"), 0);
dialog->setTitle(tr("Alert"));
dialog->setBody(message);
bool success= QObject::connect(dialog,SIGNAL(finished(bb::system::SystemUiResult::Type)),
this,
SLOT(onDialogFinishe(bb::system::SystemUiResult::Type)));
if(success){
dialog->show();
}
}
我还在我的班级顶部添加了,
using namespace bb::data;
using namespace bb::cascades;
using namespace bb::system;
SystemDialog *dialog;
我的 socketBase.h 就像,
class SocketBase: public QObject{
Q_OBJECT
public:
SocketBase(const QString &ipAddr, const ushort port) :
mIP(ipAddr), mPort(port) {
mRunThread = false;
}
enum Identity {
BAD_IDENTITY, SERVER, CLIENT
};
virtual void startThread() = 0;
virtual void stopThread() = 0;
virtual Identity getIdentity() = 0;
Q_INVOKABLE void showDialog(int id);
void onOkAlert(const QString &message);
private slots:
void onAPPFinished();
void onDialogFinishe(bb::system::SystemUiResult::Type);
}
这是应用程序终止代码
void SocketBase::onDialogFinishe(bb::system::SystemUiResult::Type)
{
qDebug()<<" dialog->result():::"<<dialog->result();
if(dialog->result()==2)
{
qDebug()<<"::: Terminate App :::";
bb::Application::exit(0);
}
}
我的代码有什么问题,请帮忙!!!