C++ Qt C++;延迟QNAM SSLERROS信号
我有一个带有启动屏幕的应用程序,我使用线程睡眠方法将其保持2秒钟。在我的窗口中,有一个对象侦听sslErrors信号,然后调用一个显示ssl错误的插槽。我不希望在启动屏幕关闭之前显示错误对话框。此应用程序还必须能够从网络文件夹运行 在我的本地机器上,它的行为与我希望的一样,但在网络驱动器上,有时会在显示启动屏幕时打开SSL错误对话框,因此当我单击对话框上的“否”按钮(用于忽略错误)时,我的应用程序崩溃:S Main.cppC++ Qt C++;延迟QNAM SSLERROS信号,c++,qt,ssl,splash-screen,C++,Qt,Ssl,Splash Screen,我有一个带有启动屏幕的应用程序,我使用线程睡眠方法将其保持2秒钟。在我的窗口中,有一个对象侦听sslErrors信号,然后调用一个显示ssl错误的插槽。我不希望在启动屏幕关闭之前显示错误对话框。此应用程序还必须能够从网络文件夹运行 在我的本地机器上,它的行为与我希望的一样,但在网络驱动器上,有时会在显示启动屏幕时打开SSL错误对话框,因此当我单击对话框上的“否”按钮(用于忽略错误)时,我的应用程序崩溃:S Main.cpp #include "mainwindow.h" #include "si
#include "mainwindow.h"
#include "single_application.h"
#include <QtCore>
#include <QApplication>
#include <QSplashScreen>
#include <QStringList>
#include <QMessageBox>
const QString CSM_VERSION = QString("v1.0i");
class MyInitThread : public QThread
{
protected:
void run(void)
{
this->sleep(2);
}
};
int main(int argc, char *argv[]) try
{
bool my_global_bool = true;
SingleApplication a(argc, argv, "CSM_CYTO_VIEWER_RUN_ONCE");
a.setProperty("my_global_bool", my_global_bool);
if (a.isRunning())
{
QMessageBox::information(0, "Cyto Viewer " + CSM_VERSION, "Cyto Viewer is already running.");
return 0;
}
//QApplication a(argc, argv);
QApplication::setWindowIcon(QIcon(":/logo/csm.ico"));
QApplication::setApplicationName(QString("Cyto Viewer"));
QApplication::setApplicationVersion(QString(CSM_VERSION));
//Check if system has a system tray
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray "
"on this system."));
return 1;
}
Q_ASSERT( QSslSocket::supportsSsl() );
MainWindow w;
QPixmap pixmap(":/splash/splash.png");
QSplashScreen splash(pixmap,Qt::WindowStaysOnTopHint);
w.setWindowOpacity(0);
w.setWindowTitle("Cyto Viewer " + CSM_VERSION);
splash.show();
QEventLoop loop;
MyInitThread *thread = new MyInitThread();
QObject::connect(thread, SIGNAL(finished()), &loop, SLOT(quit()));
QObject::connect(thread, SIGNAL(finished()), &splash, SLOT(close()));
QObject::connect(thread, SIGNAL(finished()), &w, SLOT(slInit()));
thread->start();
loop.exec();
w.show();
return a.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(view->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )),
this, SLOT(onSslErrors(QNetworkReply*, const QList<QSslError> & )));
}
#包括“mainwindow.h”
#包括“单一应用程序.h”
#包括
#包括
#包括
#包括
#包括
常量QString CSM_VERSION=QString(“v1.0i”);
类MyInitThread:publicqthread
{
受保护的:
无效运行(无效)
{
这->睡眠(2);
}
};
intmain(intargc,char*argv[])尝试
{
bool my_global_bool=true;
单个应用程序a(argc、argv,“CSM细胞查看器运行一次”);
a、 setProperty(“我的全局”,我的全局);
如果(a.isRunning())
{
QMessageBox::信息(0,“Cyto Viewer”+CSM_版本,“Cyto Viewer已在运行”);
返回0;
}
//质量保证申请a(argc、argv);
QApplication::setWindowIcon(QIcon(:/logo/csm.ico));
QApplication::setApplicationName(QString(“Cyto查看器”);
QApplication::setApplicationVersion(QString(CSM_版本));
//检查系统是否有系统托盘
如果(!QSystemTrayIcon::isSystemTrayAvailable()){
QMessageBox::critical(0,QObject::tr(“Systray”),
tr(“我无法检测到任何系统托盘”
“在这个系统上。”);
返回1;
}
Q_断言(QSslSocket::supportsSsl());
主窗口w;
QPixmap pixmap(:/splash/splash.png”);
QSplashScreen splash(pixmap,Qt::WindowStaysOnTopHint);
w、 设置窗口不透明度(0);
w、 setWindowTitle(“Cyto Viewer”+CSM_版本);
splash.show();
QEventLoop循环;
MyInitThread*thread=新的MyInitThread();
连接(线程、信号(finished())、循环、插槽(quit());
连接(线程、信号(finished())、飞溅、插槽(close());
连接(线程,信号(finished()),&w,插槽(slInit());
线程->开始();
loop.exec();
w、 show();
返回a.exec();
}
main window.cpp
#include "mainwindow.h"
#include "single_application.h"
#include <QtCore>
#include <QApplication>
#include <QSplashScreen>
#include <QStringList>
#include <QMessageBox>
const QString CSM_VERSION = QString("v1.0i");
class MyInitThread : public QThread
{
protected:
void run(void)
{
this->sleep(2);
}
};
int main(int argc, char *argv[]) try
{
bool my_global_bool = true;
SingleApplication a(argc, argv, "CSM_CYTO_VIEWER_RUN_ONCE");
a.setProperty("my_global_bool", my_global_bool);
if (a.isRunning())
{
QMessageBox::information(0, "Cyto Viewer " + CSM_VERSION, "Cyto Viewer is already running.");
return 0;
}
//QApplication a(argc, argv);
QApplication::setWindowIcon(QIcon(":/logo/csm.ico"));
QApplication::setApplicationName(QString("Cyto Viewer"));
QApplication::setApplicationVersion(QString(CSM_VERSION));
//Check if system has a system tray
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray "
"on this system."));
return 1;
}
Q_ASSERT( QSslSocket::supportsSsl() );
MainWindow w;
QPixmap pixmap(":/splash/splash.png");
QSplashScreen splash(pixmap,Qt::WindowStaysOnTopHint);
w.setWindowOpacity(0);
w.setWindowTitle("Cyto Viewer " + CSM_VERSION);
splash.show();
QEventLoop loop;
MyInitThread *thread = new MyInitThread();
QObject::connect(thread, SIGNAL(finished()), &loop, SLOT(quit()));
QObject::connect(thread, SIGNAL(finished()), &splash, SLOT(close()));
QObject::connect(thread, SIGNAL(finished()), &w, SLOT(slInit()));
thread->start();
loop.exec();
w.show();
return a.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(view->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )),
this, SLOT(onSslErrors(QNetworkReply*, const QList<QSslError> & )));
}
MainWindow::MainWindow(QWidget*父项):
QMainWindow(父级),
用户界面(新用户界面::主窗口)
{
用户界面->设置用户界面(此);
连接(查看->页面()->networkAccessManager(),信号(sslErrors(QNetworkReply*,const QList&)),
这个插槽(onsserrors(QNetworkReply*,constqlist&));
}
SSL错误插槽
void MainWindow::onSslErrors(QNetworkReply* reply, const QList<QSslError> &errors)
{
if(SSL_ONCE != true){
QString errorString;
bool firstError = false;
//TODO: Get this displaying cirtificate errors
foreach (const QSslError e, errors)
{
if(firstError != true) {
if (!errorString.isEmpty())
errorString += "";
if(e.error() != e.NoError){
errorString += "<ul style=\"background: url(minus-small.png);\"><li style=\"background: url(minus-small.png);\">" + e.errorString() + "</li></ul>";
}
}
}
//Delay MessageBox until the splash screen closes (2 seconds)
//delay(2.5);
QEventLoop loop;
MainWinThread *thread = new MainWinThread();
connect(thread, SIGNAL(finished()), &loop, SLOT(quit()));
//Detect any SSL errors from the network reply
thread->start();
loop.exec(); //Do event processing until the thread has finished!
QMessageBox sslQuestion;
//Fix for QMessageBox width
QSpacerItem horizontalSpacer(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
sslQuestion.setText("Cyto Viewer " + CSM_VERSION);
QGridLayout* layout = (QGridLayout*)sslQuestion.layout();
sslQuestion.setInformativeText("The following SSL error(s) occured: " + errorString + "Do you wish to continue?");
sslQuestion.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
sslQuestion.setIconPixmap(QPixmap(":/logo/lock-ssl.png"));
sslQuestion.setDefaultButton(QMessageBox::No);
sslQuestion.setWindowFlags(Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
sslQuestion.setMinimumWidth(800);
layout->addItem(&horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
int SSLChoice = sslQuestion.exec();
if (SSLChoice == QMessageBox::No) {
reply->abort();
delete systray;
exit(EXIT_FAILURE);
//qApp->quit();
//return;
} else {
reply->ignoreSslErrors(/*errors*/);
SSL_ONCE = true;
}
} else {
reply->ignoreSslErrors();
return;
}
}
void主窗口::onsserrors(QNetworkReply*reply,const QList&errors)
{
if(SSL_ONCE!=true){
QString错误字符串;
bool firstError=false;
//TODO:获取此文件以显示错误
foreach(常量QSslError e,错误)
{
if(firstError!=true){
如果(!errorString.isEmpty())
errorString+=“”;
如果(e.error()!=e.NoError){
errorString+=“- ”+e.errorString()+“
”;
}
}
}
//延迟MessageBox直到启动屏幕关闭(2秒)
//延误(2.5);
QEventLoop循环;
MainWinThread*线程=新的MainWinThread();
连接(线程、信号(finished())、循环和插槽(quit());
//从网络回复中检测任何SSL错误
线程->开始();
loop.exec();//执行事件处理,直到线程完成!
QMessageBox SSL问题;
//QMessageBox宽度的修复
QSpacerItem水平间隔(500,0,QSizePolicy::Minimum,QSizePolicy::Expanding);
sslQuestion.setText(“细胞查看器”+CSM_版本);
QGridLayout*布局=(QGridLayout*)sslQuestion.layout();
sslQuestion.setInformativeText(“发生了以下SSL错误:“+errorString+”是否要继续?”);
sslQuestion.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
sslQuestion.setIconPixmap(QPixmap(“:/logo/lock ssl.png”);
sslQuestion.setDefaultButton(QMessageBox::否);
sslQuestion.setWindowFlags(Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
SSL问题。设置最小宽度(800);
布局->添加项(&HorizontalSpaker,布局->行计数(),0,1,布局->列计数());
int SSLChoice=sslQuestion.exec();
if(SSLChoice==QMessageBox::否){
回复->中止();
删除systray;
退出(退出失败);
//qApp->quit();
//返回;
}否则{
回复->忽略错误(/*错误*/);
SSL_ONCE=true;
}
}否则{
答复->忽略错误();
返回;
}
}
我的slinit插槽(用于设置系统托盘/隐藏主窗口)
void主窗口::slInit()
{
设置窗口不透明度(1);
//设置最小大小,可通过注册表更改
此->设置最小大小(800640);
//系统托盘
aboutAction=新QAction(“关于”,this);
quitAction=新的QAction(“退出”,本);
连接(关于触控,信号(已触发()),此,S