QT 之啟動畫面
阿新 • • 發佈:2018-11-15
程式啟動之前有時候需要一段時間來載入, 為了避免使用者感覺程式宕機卡頓的情況,特別加上開機介面,提醒使用者程式正在執行中.
int main(int argc, char *argv[]) { QApplication a(argc, argv); std::string cur_path(""); if (!Logging::GetCurrentPath(cur_path)) { std::cout << "Get current path failed!" << std::endl; } cur_path += std::string(project_name) + std::string("/"); std::string img_path += cur_path + std::string("/") + std::string("loginImage.png") ; QString str_tmp = QString::fromStdString(img_path); QSplashScreen *splash = new QSplashScreen; QPixmap pixmap(str_tmp); pixmap = pixmap.scaled(400,400,Qt::KeepAspectRatio); splash->setPixmap(pixmap); splash->setFont((QFont("Helvetica",20))); splash->show(); Qt::Alignment topLeft = Qt::AlignLeft|Qt::AlignTop; splash->showMessage("系統啟動中,請稍等...",topLeft,Qt::white); a.processEvents(); MainDlg s(cur_path); s.show(); splash->finish(&s); delete splash; return a.exec(); }