FileSaveDialog::FileSaveDialog(QQuickItem *parent) : QQuickItem(parent) , m_dlgHelper(init_helper()) , m_modality(Qt::WindowModal) , m_options(QSharedPointer<QFileDialogOptions>(new QFileDialogOptions())) { /* * Qt Widgets support must be present, i.e. the main app is a QApplication. * The following line break at compile time, if the main app is a QGuiApplication */ QApplication *appHasQtWidgetsSupport = qobject_cast<QApplication *>(QCoreApplication::instance()); // Q_ASSERT(appHasQtWidgetsSupport); Q_UNUSED(appHasQtWidgetsSupport); if (valid()) { connect(m_dlgHelper, &QPlatformFileDialogHelper::accept, this, &FileSaveDialog::accept); connect(m_dlgHelper, &QPlatformFileDialogHelper::reject, this, &FileSaveDialog::reject); } }
static const bool init ; }; std::map< std::string, profile::setter_type > profile::setters ; // helper function to populate the map bool profile::init_helper() { setters["id"] = &profile::set_id ; setters["height"] = &profile::set_height ; setters["width"] = &profile::set_width ; // etc. return true ; } const bool profile::init = init_helper() ; // populates map by calling init_helper() std::ostream& operator<< ( std::ostream& stm, const profile& p ) { return stm << "profile { id:" << p.id << ", height:" << p.height << ", width:" << p.width << " }" ; } int main() { profile p ; std::cout << p << '\n' ; p.set( "id", "local" ) ; std::cout << p << '\n' ;