+ qRegisterMetaType<pv::util::Timestamp>("util::Timestamp");
+ qRegisterMetaType<uint64_t>("uint64_t");
+
+ // Prepare the global settings since logging needs them early on
+ pv::GlobalSettings settings;
+ settings.save_internal_defaults();
+ settings.set_defaults_where_needed();
+ settings.apply_theme();
+
+ pv::logging.init();
+
+ // Initialise libsigrok
+ context = sigrok::Context::create();
+ pv::Session::sr_context = context;
+
+#if ENABLE_STACKTRACE
+ QString temp_path = QStandardPaths::standardLocations(
+ QStandardPaths::TempLocation).at(0);
+ stacktrace_filename = temp_path + "/pv_stacktrace.dmp";
+ qDebug() << "Stack trace file is" << stacktrace_filename;
+
+ ::signal(SIGSEGV, &signal_handler);
+ ::signal(SIGABRT, &signal_handler);
+
+ if (QFileInfo::exists(stacktrace_filename))
+ process_stacktrace(temp_path);
+#endif
+
+#ifdef ANDROID
+ context->set_resource_reader(&asset_reader);
+#endif
+ do {
+
+#ifdef ENABLE_DECODE
+ // Initialise libsigrokdecode
+ if (srd_init(nullptr) != SRD_OK) {
+ qDebug() << "ERROR: libsigrokdecode init failed.";
+ break;
+ }
+
+ // Load the protocol decoders
+ srd_decoder_load_all();
+#endif
+
+#ifndef ENABLE_STACKTRACE
+ try {
+#endif
+
+ // Create the device manager, initialise the drivers
+ pv::DeviceManager device_manager(context, driver, do_scan);
+
+ a.collect_version_info(context);
+ if (show_version) {
+ a.print_version_info();
+ } else {
+ // Initialise the main window
+ pv::MainWindow w(device_manager);
+ w.show();
+
+ if (restore_sessions)
+ w.restore_sessions();
+
+ if (open_files.empty())
+ w.add_default_session();
+ else
+ for (string& open_file : open_files)
+ w.add_session_with_file(open_file, open_file_format, open_setup_file);
+
+#ifdef ENABLE_SIGNALS
+ if (SignalHandler::prepare_signals()) {
+ SignalHandler *const handler = new SignalHandler(&w);
+ QObject::connect(handler, SIGNAL(int_received()),
+ &w, SLOT(close()));
+ QObject::connect(handler, SIGNAL(term_received()),
+ &w, SLOT(close()));
+ } else
+ qWarning() << "Could not prepare signal handler.";
+#endif
+
+ // Run the application
+ ret = a.exec();
+ }
+
+#ifndef ENABLE_STACKTRACE
+ } catch (exception& e) {
+ qDebug() << "Exception:" << e.what();
+ }
+#endif