我的BB 10级联中有一个套接字连接App,当套接字连接关闭时,我需要显示一个对话框,当按下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");
}
}
void 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);
}
}
我的代码有什么问题,请帮助!!!