本文整理汇总了C++中QQmlApplicationEngine类的典型用法代码示例。如果您正苦于以下问题:C++ QQmlApplicationEngine类的具体用法?C++ QQmlApplicationEngine怎么用?C++ QQmlApplicationEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QQmlApplicationEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
Logger::Init("Tombola.log.txt");
qInfo() << "\n\n" << "========== Startup ==========";
CrashHandler crashHandler;
QApplication app(argc, argv);
QCoreApplication::setApplicationName("Tombola"); // QSettings init early enough
QCoreApplication::setOrganizationName("Kúr Attila"); // QSettings init early enough
DynamicTranslation dynamicTranslation(app);
TombolaDocument document;
// qmlRegisterType<BlockColorsSet_ViewModel>("com.quatso.tombola", 1, 0, "BlockColorSetListModel");
TicketDrawExecutor ticketDrawExecutor( document
, new SingleTicketDraw_ViewModel()
, new SingleTicketDraw_ViewModel());
Controller controller(document, ticketDrawExecutor);
controller.OnAppStartup();
TicketsSellingPoint_ViewModel ticketsSellingPoint_ViewModel(document);
ticketsSellingPoint_ViewModel.Init(ticketDrawExecutor.IsPrizeDrawingRunning());
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("ticketsSellingPoint", QVariant::fromValue(&ticketsSellingPoint_ViewModel));
engine.rootContext()->setContextProperty("ticketDrawExecutor", QVariant::fromValue(&ticketDrawExecutor));
engine.rootContext()->setContextProperty("dynamicTranslation", &dynamicTranslation);
engine.rootContext()->setContextProperty("crashHandler", &crashHandler);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QIcon appIcon(":///Images/TombolaAppIcon.png");
app.setWindowIcon(appIcon);
int appRetVal = app.exec();
controller.OnAppExit();
return appRetVal;
}
示例2: run_ui
void run_ui()
{
#ifdef SUBSURFACE_MOBILE
QQmlApplicationEngine engine;
register_qml_types(&engine);
LOG_STP("run_ui qml engine started");
KirigamiPlugin::getInstance().registerTypes();
#if defined(__APPLE__) && !defined(Q_OS_IOS)
// when running the QML UI on a Mac the deployment of the QML Components seems
// to fail and the search path for the components is rather odd - simply the
// same directory the executable was started from <bundle>/Contents/MacOS/
// To work around this we need to manually copy the components at install time
// to Contents/Frameworks/qml and make sure that we add the correct import path
const QStringList importPathList = engine.importPathList();
for (QString importPath: importPathList) {
if (importPath.contains("MacOS"))
engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
}
qDebug() << "QML import path" << engine.importPathList();
#endif // __APPLE__ not Q_OS_IOS
engine.addImportPath("qrc://imports");
DiveListModel diveListModel;
LOG_STP("run_ui diveListModel started");
DiveListSortModel *sortModel = new DiveListSortModel(0);
sortModel->setSourceModel(&diveListModel);
sortModel->setDynamicSortFilter(true);
sortModel->setSortRole(DiveListModel::DiveDateRole);
sortModel->sort(0, Qt::DescendingOrder);
LOG_STP("run_ui diveListModel sorted");
GpsListModel gpsListModel;
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(0);
gpsSortModel->setSourceModel(&gpsListModel);
gpsSortModel->setDynamicSortFilter(true);
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
gpsSortModel->sort(0, Qt::DescendingOrder);
QQmlContext *ctxt = engine.rootContext();
ctxt->setContextProperty("diveModel", sortModel);
ctxt->setContextProperty("gpsModel", gpsSortModel);
ctxt->setContextProperty("vendorList", vendorList);
set_non_bt_addresses();
LOG_STP("run_ui set_non_bt_adresses");
ctxt->setContextProperty("connectionListModel", &connectionListModel);
ctxt->setContextProperty("logModel", MessageHandlerModel::self());
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
LOG_STP("run_ui qml loaded");
qqWindowObject = engine.rootObjects().value(0);
if (!qqWindowObject) {
fprintf(stderr, "can't create window object\n");
exit(1);
}
QQuickWindow *qml_window = qobject_cast<QQuickWindow *>(qqWindowObject);
qml_window->setIcon(QIcon(":subsurface-mobile-icon"));
qDebug() << "qqwindow devicePixelRatio" << qml_window->devicePixelRatio() << qml_window->screen()->devicePixelRatio();
QScreen *screen = qml_window->screen();
QObject::connect(qml_window, &QQuickWindow::screenChanged, QMLManager::instance(), &QMLManager::screenChanged);
QMLManager *manager = QMLManager::instance();
LOG_STP("run_ui qmlmanager instance started");
// now that the log file is initialized...
show_computer_list();
LOG_STP("run_ui show_computer_list");
manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
manager->dlSortModel = sortModel;
manager->qmlWindow = qqWindowObject;
manager->screenChanged(screen);
qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
qml_window->setHeight(1200);
qml_window->setWidth(800);
#endif // not Q_OS_ANDROID and not Q_OS_IOS
qml_window->show();
LOG_STP("run_ui running exec");
#else
MainWindow::instance()->show();
#endif // SUBSURFACE_MOBILE
qApp->exec();
}
示例3: main
int main( int argc, char *argv[] ) {
// Init controller db file for backend
Q_INIT_RESOURCE( controllerdb );
// Uncomment this to enable the message handler for debugging and stack tracing
// qInstallMessageHandler( phoenixDebugMessageHandler );
// Handles stuff with the windowing system
QGuiApplication app( argc, argv );
// The engine that runs our QML-based UI
QQmlApplicationEngine engine;
// Set application metadata
QGuiApplication::setApplicationDisplayName( QStringLiteral( "Phoenix" ) );
QGuiApplication::setApplicationName( QStringLiteral( "Phoenix" ) );
QGuiApplication::setApplicationVersion( QStringLiteral( "0.0.1" ) );
QGuiApplication::setOrganizationName( QStringLiteral( "Team Phoenix" ) );
QGuiApplication::setOrganizationDomain( QStringLiteral( "phoenix.vg" ) );
// Figure out the right paths for the environment, and create user storage folders if not already there
Library::PhxPaths::initPaths();
// For release builds, write to a log file along with the console
#ifdef QT_NO_DEBUG
QFile logFile( Library::PhxPaths::userDataLocation() % '/' % QStringLiteral( "Logs" ) % '/' %
QDateTime::currentDateTime().toString( QStringLiteral( "ddd MMM d yyyy - h mm ss AP" ) ) %
QStringLiteral( ".log" ) );
// If this fails... how would we know? :)
logFile.open( QIODevice::WriteOnly | QIODevice::Text );
int logFD = logFile.handle();
logFP = fdopen( dup( logFD ), "w" );
qInstallMessageHandler( phoenixDebugMessageLog );
#endif
// Open connections to the SQL databases.
Library::LibretroDatabase::open();
Library::MetaDataDatabase::open();
// Necessary to quit properly
QObject::connect( &engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit );
// Register our custom types for use within QML
VideoItem::registerTypes();
InputManager::registerTypes();
// Register our custom QML-accessable/instantiable objects
qmlRegisterType<Library::PlatformsModel>( "vg.phoenix.models", 1, 0, "PlatformsModel" );
qmlRegisterType<Library::CollectionsModel>( "vg.phoenix.models", 1, 0, "CollectionsModel" );
qmlRegisterType<Library::LibraryModel>( "vg.phoenix.models", 1, 0, "LibraryModel" );
qmlRegisterType<Library::CoreModel>( "vg.phoenix.models", 1, 0, "CoreModel" );
qmlRegisterType<Library::ImageCacher>( "vg.phoenix.cache", 1, 0, "ImageCacher" );
qmlRegisterType<GameLauncher>( "vg.phoenix.launcher", 1, 0, "GameLauncher" );
// Register our custom QML-accessable objects and instantiate them here
qmlRegisterSingletonType( QUrl( "qrc:/PhxTheme.qml" ), "vg.phoenix.themes", 1, 0, "PhxTheme" );
qmlRegisterSingletonType<Library::PhxPaths>( "vg.phoenix.paths", 1, 0, "PhxPaths", PhxPathsSingletonProviderCallback );
qRegisterMetaType<Library::GameData>( "GameData" );
// Load the root QML object and everything under it
engine.load( QUrl( QStringLiteral( "qrc:/main.qml" ) ) );
// Ensure custom controller DB file exists
QFile gameControllerDBFile( Library::PhxPaths::userDataLocation() % '/' % QStringLiteral( "gamecontrollerdb.txt" ) );
if( !gameControllerDBFile.exists() ) {
gameControllerDBFile.open( QIODevice::ReadWrite );
QTextStream stream( &gameControllerDBFile );
stream << "# Insert your custom definitions here" << endl;
gameControllerDBFile.close();
}
// Set InputManager's custom controller DB file
QQmlProperty prop( engine.rootObjects().first(), "inputManager.controllerDBFile" );
Q_ASSERT( prop.isValid() );
QString path = Library::PhxPaths::userDataLocation() % QStringLiteral( "/gamecontrollerdb.txt" );
QVariant pathVar( path );
prop.write( pathVar );
// Run the app and write return code to the log file if in release mode
#ifdef QT_NO_DEBUG
int ret = app.exec();
fprintf( logFP, "Returned %d", ret );
fclose( logFP );
return ret;
#else
// Otherwise, just run it normally
return app.exec();
#endif
}
示例4: main
int main(int argc, char *argv[])
{
try
{
QCommandLineParser parser;
parser.setApplicationDescription("Plex Media Player");
parser.addHelpOption();
parser.addVersionOption();
parser.addOptions({{{"l", "licenses"}, "Show license information"}});
parser.addOptions({{{"a", "from-auto-update"}, "When invoked from auto-update"}});
char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags);
argc += g_qtFlags.size();
// Suppress SSL related warnings on OSX
// See https://bugreports.qt.io/browse/QTBUG-43173 for more info
//
#ifdef Q_OS_MAC
qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false");
#endif
// Qt calls setlocale(LC_ALL, "") in a bunch of places, which breaks
// float/string processing in mpv and ffmpeg.
#ifdef Q_OS_UNIX
qputenv("LC_ALL", "C");
qputenv("LC_NUMERIC", "C");
#endif
detectOpenGLEarly();
preinitQt();
QGuiApplication app(argc, newArgv);
app.setWindowIcon(QIcon(":/images/icon.png"));
// Get the arguments from the app, this is the parsed version of newArgc and newArgv
QStringList args = app.arguments();
// Remove the qt flags above so that our command line parser doesn't get cranky.
for (auto flag : g_qtFlags)
args.removeAll(flag);
// Now parse the command line.
parser.process(args);
if (parser.isSet("licenses"))
{
ShowLicenseInfo();
return EXIT_SUCCESS;
}
// init breakpad.
setupCrashDumper();
UniqueApplication* uniqueApp = new UniqueApplication();
if (!uniqueApp->ensureUnique())
return EXIT_SUCCESS;
#ifdef Q_OS_UNIX
// install signals handlers for proper app closing.
SignalManager signalManager(&app);
Q_UNUSED(signalManager);
#endif
Log::Init();
// Quit app and apply update if we find one.
if (UpdateManager::CheckForUpdates())
{
app.quit();
return 0;
}
detectOpenGLLate();
#ifdef Q_OS_WIN32
initD3DDevice();
#endif
Codecs::preinitCodecs();
// Initialize all the components. This needs to be done
// early since most everything else relies on it
//
ComponentManager::Get().initialize();
// enable remote inspection if we have the correct setting for it.
if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");
QtWebEngine::initialize();
// start our helper
HelperLauncher::Get().connectToHelper();
// load QtWebChannel so that we can register our components with it.
QQmlApplicationEngine *engine = Globals::Engine();
KonvergoWindow::RegisterClass();
Globals::SetContextProperty("components", &ComponentManager::Get().getQmlPropertyMap());
//.........这里部分代码省略.........
示例5: main
int main(int argc, char** argv) {
srand(time(NULL)); // init rand;
#if PORTAL
Portal p(Segment(10, 40, 10, 20), Segment(40, 10, 20, 10));
std::vector<Segment> lines(p.deviateLine(Segment(20, 40, 0, 30)));
for (const Segment& line: lines)
std::cerr << line << std::endl;
#endif
#if Thumbnail
QApplication app(argc, argv);
PolygonList polygonList;
//polygonList << poc::Polygon(30, 250, 21, 260, 5);
poc::Polygon polygon;
polygon << Point2d(55, 55)
<< Point2d(455, 55)
<< Point2d(455, 455)
<< Point2d(155, 455)
<< Point2d(155, 255)
<< Point2d(255, 255)
<< Point2d(255, 355)
<< Point2d(355, 355)
<< Point2d(355, 155)
<< Point2d(55, 155);
polygonList << polygon;
qDebug() << polygonList;
ThumbnailCreator thumbnailCreator(polygonList);
QImage thumbnail = thumbnailCreator.makeThumbnail();
QLabel* label = new QLabel;
label->setPixmap(QPixmap::fromImage(thumbnail));
label->show();
return app.exec();
#endif
#if TESTPOINT
Test::test<< Point2d();
#endif
#if TESTVECTOR
Test::testVector2d();
#endif
#if TESTPOLYGON
Test::testPolygon();
#endif
#if GUI
QApplication app(argc, argv);
// QFontDatabase::addApplicationFont("../PieceOfCake/fonts/edosz.ttf");
// QFontDatabase::addApplicationFont("../PieceOfCake/fonts/watermark.ttf");
qmlRegisterType<GameInfo>("gameinfo", 1, 0, "GameInfo");
qmlRegisterType<LevelInfo>("levelinfo", 1, 0, "LevelInfo");
MainWindow window;
window.show();
return app.exec();
#endif
#if QML
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
#endif
#if GNUPLOT
// poc::Polygon polygon;
// polygon << << Point2d() << << Point2d(0, 1) << << Point2d(1, 1) << << Point2d(1);
poc::Polygon polygon(0, 100, 0, 100, 7);
// std::vector<Point2d> vertices = polygon.getVertices();
// for (unsigned int k = 0; k < vertices.size(); ++k)
// std::cerr << vertices.at(k).getX() << " " << vertices.at(k).getY() << " " << -10 << std::endl;
float size = 300;
float delta = 10;
int max = size/delta;
float** matrix = polygon.surface(size, delta);
for (int i = 0; i < max; ++i) {
for (int j = 0; j < max; ++j) {
std::cerr << i << " " << j << " " << matrix[i][j] << std::endl;
}
delete[] matrix[i];
}
delete[] matrix;
#endif
//.........这里部分代码省略.........
示例6: main
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
QApplication app(argc, argv);
app.setOrganizationName("Qtness");
app.setOrganizationDomain("qtness.com");
app.setApplicationName("Sachesi");
app.setApplicationVersion("2.0.0");
// Use system proxy except where not possible
QNetworkProxyFactory::setUseSystemConfiguration(true);
QQmlApplicationEngine engine;
QQmlContext *context = engine.rootContext();
// Do we have a suitable place to store files that the user will be able to find?
if (!checkCurPath()) {
QMessageBox::critical(NULL, "Error", "Could not find a suitable storage path.\nPlease report this.");
return 0;
}
// *** Static QML Variables that describe the environment
// Useful as QML is unable to detect this natively
// Send the version across. Preferably via the .pro
context->setContextProperty("version", QVariant::fromValue(QApplication::applicationVersion()));
// Check if we have at least Qt 5.3 available. If not, do some workarounds for bugs.
context->setContextProperty("qt_new", QVariant::fromValue(QT_VERSION > QT_VERSION_CHECK(5, 3, 0)));
// Check if this is a mobile device as they often do not have enough space.
context->setContextProperty("mobile", QVariant::fromValue(
#if defined(BLACKBERRY) || defined(ANDROID)
1
#else
0
#endif
));
// *** C++ Classes that are passed to the QML pages.
// Heavy lifting to be done by the compiled and feature-packed language.
InstallNet i;
context->setContextProperty("i", &i);
MainNet p(&i);
Scanner scanner;
Translator translator;
#ifdef BOOTLOADER_ACCESS
Boot b;
QObject::connect(&b, SIGNAL(started()), &b, SLOT(search()));
QObject::connect(&b, SIGNAL(finished()), &b, SLOT(exit()));
QObject::connect(&i, SIGNAL(newPassword(QString)), &b, SLOT(newPassword(QString)));
b.start();
context->setContextProperty("b", &b); // Boot
#endif
CarrierInfo info;
// Set contexts for the classes
context->setContextProperty("p", &p); // MainNet
context->setContextProperty("scanner", &scanner);
context->setContextProperty("download", p.currentDownload);
context->setContextProperty("carrierinfo", &info);
context->setContextProperty("translator", &translator);
// *** Register types for the QML language to understand types used by C++, when passed
#ifndef BLACKBERRY
qmlRegisterType<BackupInfo>("BackupTools", 1, 0, "BackupInfo");
#endif
qmlRegisterType<Apps>();
qmlRegisterType<DeviceInfo>();
qmlRegisterType<DiscoveredRelease>();
#if defined(_WIN32) && defined(STATIC)
engine.addImportPath("qrc:/qml/");
#endif
// *** Now let's try to show the QML file and check for errors
QScopedPointer<QQmlComponent> comp(new QQmlComponent(&engine));
comp->loadUrl(QUrl("qrc:/qml/generic/Title.qml"));
if (comp->status() == QQmlComponent::Error) {
QMessageBox::information(nullptr, "Error", qPrintable(comp->errorString()), QMessageBox::Ok);
return 0;
}
QQuickWindow *window = qobject_cast<QQuickWindow *>(comp->create());
window->show();
int ret = app.exec();
#ifdef BOOTLOADER_ACCESS
b.quit();
b.wait(1000);
#endif
delete window;
return ret;
}
示例7: main
int main(int argc, char *argv[])
{
Py_SetProgramName(GetWC(argv[0]));
qDebug()<<"Version Of QT: "<<qVersion();
// Load env from QML path
char* qml_env_path;
qml_env_path = getenv("AFERMER_QML_PATH");
fs::path qml_app_path("/");
if (qml_env_path == NULL)
{
std::cerr << "AFERMER_QML_PATH not present or directory does not exist. Take directory from startup " << std::endl;
fs::path full_path( fs::initial_path<fs::path>() );
full_path = fs::system_complete( fs::path( argv[0] ) );
qml_app_path = full_path.parent_path() / "qml";
if (!fs::exists( qml_app_path ))
{
std::cerr << "QML directory ("
<< qml_app_path
<< ") not found. Exit" << std::endl;
return 1;
}
}
else
{
qml_app_path = fs::path(qml_env_path);
}
fs::path qml_app_icon_path(qml_app_path);
qml_app_icon_path /= "icons";
qml_app_icon_path /= "soft_circl_icon.png";
qml_app_path /= "main.qml";
QGuiApplication app(argc, argv);
app.setOrganizationName("afermer");
app.setWindowIcon(QIcon(qml_app_icon_path.string().c_str()));
BladeState::declareQML();
JobState::declareQML();
TaskState::declareQML();
QQmlApplicationEngine engine;
General general;
JobsModel jobs_model;
BladesModel blades_model;
UsersModel users_model;
TasksModel tasks_model;
QQmlContext *ctxt =engine.rootContext();
//ctxt->setContextProperty("server_exist", "yes");
ctxt->setContextProperty("General", &general);
ctxt->setContextProperty("JobsModel", &jobs_model);
ctxt->setContextProperty("BladesModel", &blades_model);
ctxt->setContextProperty("UsersModel", &users_model);
ctxt->setContextProperty("TasksModel", &tasks_model);
engine.load(QUrl::fromLocalFile(qml_app_path.string().c_str()));
QObject *rootObject = engine.rootObjects().first();
rootObject->setProperty("visible", true);
engine.collectGarbage();
return app.exec();
}
示例8: main
int main(int argc, char *argv[]){
QTime t;
t.start();
//START APP
QApplication app(argc,argv);
app.setWindowIcon(QIcon(":/data/img/11412394_407750046078820_6932822019341529347_n.jpg"));
QApplication::setApplicationName("Huffman");
QApplication::setApplicationVersion("ÚNICO");
QQmlApplicationEngine engine;
QQmlContext *interpreter = engine.rootContext();
Huffman huff;
DHuffman deHuff;
QCommandLineParser parser;
//Parser
parser.addHelpOption();
parser.addVersionOption();
parser.setApplicationDescription("Huffman Parsers");
parser.addPositionalArgument("in-file.x", QCoreApplication::translate("main", "File being compressed."));
parser.addPositionalArgument("out-name.huff", QCoreApplication::translate("main", "Name to save archive."));
//parser.addPositionalArgument("dir", QCoreApplication::translate("main", "Dir being compressed"));
parser.addPositionalArgument("local", QCoreApplication::translate("main", "Local to save archive."));
QCommandLineOption compress("c",QApplication::translate("main","Compress <in-file.x>."),
QApplication::translate("main","in-file.x"));
parser.addOption(compress);
QCommandLineOption outName("o",QApplication::translate("main","Save as <out-name.huff>."),
QApplication::translate("main","out-file.huff"));
parser.addOption(outName);
QCommandLineOption local("d",QApplication::translate("main","Decompress in <local>."),
QApplication::translate("main","local"));
parser.addOption(local);
QCommandLineOption startGui({"g", "gui"},QApplication::translate("main","Start gui."));
parser.addOption(startGui);
parser.process(app);
//ARGUMENTS
if(parser.isSet(startGui)){
interpreter->setContextProperty("_huff",&huff);
interpreter->setContextProperty("_dehuff",&deHuff);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
}
else if(parser.isSet(compress) && parser.isSet(outName))
{
cout << "case 1" << endl;
huff.Huff(parser.value(compress),parser.value(outName));
}
else if(parser.isSet(compress))
{
cout << "case 2" << endl;
huff.Huff(parser.value(compress),parser.value(compress));
}
else{
if(app.arguments().size() == 1)
qDebug() << qPrintable(parser.helpText());
else if(parser.isSet(local))
deHuff.DHuff(app.arguments().at(1),parser.value(local));
else
deHuff.DHuff(app.arguments().at(1),app.arguments().at(1));
}
//END APP
qDebug("%s <> Tempo de execução: %d ms",Q_FUNC_INFO,t.elapsed());
return app.exec();
}
示例9: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextStream out(stdout);
out << "Hello world!" << endl;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("basic.sqlite");
bool ok = db.open();
out << "What is the database name? " << db.databaseName() << endl;
out << "Did I connect to " << db.databaseName() << "? " << ok << endl;
out << "Is the connection valid? " << db.isValid() << endl;
out << "Is the connection open? " << db.isOpen() << endl;
out << "What is the driver name? " << db.driverName() << endl;
out << "What is the host name? " << db.hostName() << endl;
out << "What is the connection name? " << db.connectionName() << endl;
out << "What are the connection options? " << db.connectOptions() << endl;
bool hasQuerySize = db.driver()->hasFeature(QSqlDriver::QuerySize);
out << "Does sqlite support querying the result set size? " << hasQuerySize << endl;
out << "Tables:";
QStringList tables = db.tables();
foreach (QString table, tables) {
out << " " << table;
}
out << endl;
QSqlQuery query;
query.setForwardOnly(true);
query.exec("SELECT * from advances");
if (hasQuerySize) {
out << "Querying advances (" << query.size() << " results):" << endl;
} else {
out << "Querying advances:" << endl;
}
QStringList columns;
QSqlRecord record = query.record();
out << "Number of columns: " << record.count() << endl;
for (int i = 0; i < record.count(); i++) {
out << "column " << i << ": " << record.fieldName(i) << endl;
columns.append(record.fieldName(i));
}
QList<QObject*> advances;
while(query.next()) {
Civilization::Advance *advance = new Civilization::Advance();
out << "advance " << advances.size() << ":";
for (int i = 0; i < columns.size(); i++) {
out << " " << columns[i] << ": " << query.value(i).toString();
QVariant v(query.value(i).toString());
advance->setProperty(columns[i].toLatin1().data(), v);
}
out << endl;
advances.append(advance);
}
out << advances.size() << " results." << endl;
db.close();
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("advanceListModel", QVariant::fromValue(advances));
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例10: main
Q_DECL_EXPORT int main(int argc, char *argv[])
{
#ifdef Q_OS_SYMBIAN
QApplication::setAttribute((Qt::ApplicationAttribute)11); //Qt::AA_CaptureMultimediaKeys
#endif
QApplication app(argc, argv);
app.setApplicationName("QVideo");
app.setOrganizationName("QShen");
app.setApplicationVersion(VER);
QString locale = QLocale::system().name();
QTranslator translator;
if(!translator.load(QString("QVideo_") + locale,":/i18n")){
qDebug()<<"translator load erro";
}
app.installTranslator(&translator);
Utility utility;
Settings settings;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QmlApplicationViewer viewer;
//viewer.setAttribute(Qt::WA_OpaquePaintEvent);
//viewer.setAttribute(Qt::WA_NoSystemBackground);
//viewer.viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
//viewer.viewport()->setAttribute(Qt::WA_NoSystemBackground);
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.rootContext()->setContextProperty("utility", &utility);
viewer.rootContext()->setContextProperty("settings", &settings);
viewer.rootContext()->setContextProperty("appVersion", app.applicationVersion());
#ifdef Q_OS_SYMBIAN
QSplashScreen *splash = new QSplashScreen(QPixmap(":/qml/pic/splash_symbian.png"));
splash->show();
splash->raise();
viewer.setSource(QUrl("qrc:/qml/Symbian/main.qml"));
#elif defined(Q_OS_HARMATTAN)
//QApplication::setGraphicsSystem("native");
viewer.setSource(QUrl("qrc:/qml/Meego/main.qml"));
#elif defined(Q_WS_SIMULATOR)
viewer.setSource(QUrl("qrc:/qml/Symbian/main.qml"));
#endif
viewer.showExpanded();
#else
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("utility",&utility);
#ifdef Q_OS_WIN32
engine.load(QUrl(QStringLiteral("qrc:/qml/Win32/main.qml")));
#endif
#endif
#ifdef Q_OS_SYMBIAN
splash->finish(&viewer);
splash->deleteLater();
#endif
return app.exec();
}
示例11: addImportPath
void addImportPath(QQmlApplicationEngine& engine, const QString& relativePath, bool insert = false) {
QString resolvedPath = getRelativeDir(relativePath);
qDebug() << "adding import path: " << QDir::toNativeSeparators(resolvedPath);
engine.addImportPath(resolvedPath);
}
示例12: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName ("QQStars");
app.setApplicationVersion ("1.0.0");
app.setOrganizationName ("雨后星辰");
app.setApplicationDisplayName ("星辰QQ");
QTranslator *translator = new QTranslator;
translator->load (":/qt_zh_CN.qm");
QApplication::installTranslator (translator);
QQmlApplicationEngine *engine = new QQmlApplicationEngine;
engine->setNetworkAccessManagerFactory (new MyNetworkAccessManagerFactory());//给qml设置网络请求所用的类
qmlRegisterType<TextEditPlayGif>("MyTextEditPlugin", 1, 0, "TextEditPlayGif");
qmlRegisterType<MyWindow>("mywindow", 1,0, "MyQuickWindow");
qmlRegisterType<SystemTrayIcon>("mywindow", 1,0, "MySystemTrayIcon");
qmlRegisterType<MyMenu>("mywindow", 1,0, "MyMenu");
qmlRegisterType<MenuSeparator>("mywindow", 1,0, "MenuSeparator");
qmlRegisterType<MyMenuItem>("mywindow", 1,0, "MyMenuItem");
qmlRegisterType<MyShortcut>("utility", 1,0, "MyShortcut");
qmlRegisterType<DownloadImage>("utility", 1, 0, "DownloadImage");
qmlRegisterType<QQCommand>("qqstars", 1,0, "QQ");
qmlRegisterType<FriendInfo>("QQItemInfo", 1,0, "FriendInfo");
qmlRegisterType<GroupInfo>("QQItemInfo", 1,0, "GroupInfo");
qmlRegisterType<DiscuInfo>("QQItemInfo", 1,0, "DiscuInfo");
qmlRegisterType<QQItemInfo>("QQItemInfo", 1,0, "QQItemInfo");
qmlRegisterType<ChatMessageInfo>("QQItemInfo", 1, 0, "ChatMessageInfo");
qmlRegisterType<ChatMessageInfoList>("QQItemInfo", 1, 0, "ChatMessageInfoList");
qmlRegisterType<MyImage>("mywindow", 1,0, "MyImage");
qmlRegisterType<MySvgView>("mywindow", 1, 0, "SvgView");
qmlRegisterType<MyMessageBox>("mywindow", 1, 0, "MessageBox");
Utility *utility=Utility::createUtilityClass ();
QNetworkRequest* request = utility->getHttpRequest ()->getNetworkRequest ();
request->setRawHeader ("Referer", "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2");//和腾讯服务器打交道需要设置这个
request->setHeader (QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request = utility->getDownloadImage ()->getHttpRequest ()->getNetworkRequest ();
request->setRawHeader ("Referer", "http://web2.qq.com/webqq.html");//需要设置这个,不然腾讯服务器不响应你的请求
request->setRawHeader ("Accept", "image/webp,*/*;q=0.8");
utility->initUtility (new QSettings, engine);
QQmlComponent component0(engine, QUrl("qrc:/qml/Api/QQApi.qml"));
QQCommand *qqapi = qobject_cast<QQCommand *>(component0.create ());
engine->rootContext ()->setContextProperty ("myqq", qqapi);
QQmlComponent component(engine, QUrl("qrc:/qml/Utility/SystemTray.qml"));
SystemTrayIcon *systemTray = qobject_cast<SystemTrayIcon *>(component.create ());
#ifdef Q_OS_WIN
systemTray->setParent (Utility::createUtilityClass ());//不设置父对象会导致程序退出后托盘还存在的问题
#endif
engine->rootContext ()->setContextProperty ("systemTray", systemTray);//将程序托盘注册过去
qqapi->loadLoginWindow ();//加载登录窗口
return app.exec();
}
示例13: main
int main(int argc, char *argv[])
{
try {
QApplication app(argc, argv);
QString commands;
//Mac specific Terminal command
commands = "system_profiler SPHardwareDataType";
//commands = "cat abc"; /* Wrong cat file -- testing */
//commands = " abc"; /* Wrong Terminal command -- testing */
/* For Linux and Ubuntu we use -- cat /proc/cpuinfo*/
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QProcess *process = new QProcess(0);
process->setProcessChannelMode(QProcess::MergedChannels);
//process->start("system_profiler SPHardwareDataType");
process->start(commands);
QByteArray arrSysInfo;
process->write(arrSysInfo);
process->closeWriteChannel();
if(!process->waitForStarted()){
qDebug() << "Could not wait to start..."
<< process->error()
<< process->errorString();
}
if(!process->waitForFinished()) {
qDebug() << "Could not wait to finish..."
<< process->error()
<< process->errorString();
}
else{
mySysInfo output; /* interface */
output.setData( process->readAll());
QObject *rootObject = engine.rootObjects().first();
QObject* lstview = rootObject->findChild<QObject*>("lstview");
if (lstview)
lstview->setProperty("placeholderText", output.getData());//quick fix
}
return app.exec();
} catch(std::exception e) {\
qDebug() << "Exception caught in main()"
<< e.what();
}
}
示例14: main
int main(int argc, char *argv[])
{
try
{
for (int n = 1; n < argc; n++) {
if (strcmp(argv[n], "--licenses") == 0) {
QFile licenses(":/misc/licenses.txt");
licenses.open(QIODevice::ReadOnly | QIODevice::Text);
QByteArray contents = licenses.readAll();
printf("%.*s\n", (int)contents.size(), contents.data());
return 0;
}
}
int newArgc = argc;
char **newArgv = appendCommandLineArguments(&newArgc, argv);
// Supress SSL related warnings on OSX
// See https://bugreports.qt.io/browse/QTBUG-43173 for more info
//
#ifdef Q_OS_MAC
qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false");
// Request OpenGL 4.1 if possible on OSX, otherwise it defaults to 2.0
// This needs to be done before we create the QGuiApplication
//
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setMajorVersion(3);
format.setMinorVersion(2);
format.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);
#endif
QGuiApplication app(newArgc, newArgv);
initQt(&app);
// init breakpad.
setupCrashDumper();
UniqueApplication* uniqueApp = new UniqueApplication();
if (!uniqueApp->ensureUnique())
return EXIT_SUCCESS;
#ifdef Q_OS_UNIX
// install signals handlers for proper app closing.
SignalManager signalManager(&app);
Q_UNUSED(signalManager);
#endif
initLogger();
QLOG_INFO() << "Starting Plex Media Player version:" << qPrintable(Version::GetVersionString()) << "build date:" << qPrintable(Version::GetBuildDate());
QLOG_INFO() << qPrintable(QString(" Running on: %1 [%2] arch %3").arg(QSysInfo::prettyProductName()).arg(QSysInfo::kernelVersion()).arg(QSysInfo::currentCpuArchitecture()));
QLOG_INFO() << " Qt Version:" << QT_VERSION_STR << qPrintable(QString("[%1]").arg(QSysInfo::buildAbi()));
// Quit app and apply update if we find one.
if (UpdateManager::CheckForUpdates())
{
app.quit();
return 0;
}
#ifdef Q_OS_WIN32
initD3DDevice();
#endif
#ifdef Q_OS_UNIX
setlocale(LC_NUMERIC, "C");
#endif
// Initialize all the components. This needs to be done
// early since most everything else relies on it
//
ComponentManager::Get().initialize();
// enable remote inspection if we have the correct setting for it.
if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");
QtWebEngine::initialize();
// Qt and QWebEngineProfile set the locale, which breaks parsing and
// formatting float numbers in a few countries.
#ifdef Q_OS_UNIX
setlocale(LC_NUMERIC, "C");
#endif
// start our helper
HelperLauncher::Get().connectToHelper();
// load QtWebChannel so that we can register our components with it.
QQmlApplicationEngine *engine = KonvergoEngine::Get();
KonvergoWindow::RegisterClass();
engine->rootContext()->setContextProperty("components", &ComponentManager::Get().getQmlPropertyMap());
// This controls how big the web view will zoom using semantic zoom
// over a specific number of pixels and we run out of space for on screen
// tiles in chromium. This only happens on OSX since on other platforms
// we can use the GPU to transfer tiles directly but we set the limit on all platforms
// to keep it consistent.
//
//.........这里部分代码省略.........
示例15: main
int main( int argc, char* argv[] )
{
QApplication app(argc, argv);
LOGGER.setLevel( 3 );
LOGGER.setOutput( Logger::Console );
LOG( 1, "Pixout ArtNet Viewer" );
LOG( 1, "viewer Version: %s ", VERSION );
const QString settings_path = QDir::fromNativeSeparators(
QStandardPaths::writableLocation( QStandardPaths::AppLocalDataLocation ) + QDir::separator()
);
// create settings location if not exists
QDir ().mkdir( settings_path );
AppSettings settings;
if( argc < 3 )
{
if( !settings.load( settings_path + "app.data") )
{
WARN("Can't open or empty fixture file: %s", qPrintable(settings_path + "app.data") );
}
}
else {
settings.setProperty("port", atoi( argv[1] ));
settings.setProperty("fixturePath", argv[2]);
settings.setProperty("position", argv[3]);
}
QQmlApplicationEngine engine;
app.setWindowIcon(QIcon(":favicon.png"));
engine.addImportPath( QStringLiteral("qrc:/"));
qmlRegisterType<PainterOutput>("Painter", 1, 0, "PainterItem");
qmlRegisterUncreatableType<AppSettings,1>("AppSettings",1,0,"AppSettings","AppSettings couldn't be created from QML");
engine.rootContext()->setContextProperty("settings", &settings);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *rootObject = engine.rootObjects().first();
Q_ASSERT( rootObject );
PainterOutput *output( rootObject->findChild<PainterOutput*>( "painter" ) );
Q_ASSERT( output );
Painter painter( output, &settings );
PixelMapperWithError mapper( &settings );
painter.SetPixelMapper( &mapper );
Receiver receiver( &settings );
QObject::connect( &receiver, &Receiver::Received, &painter, &Painter::Draw );
QObject::connect( &painter, &Painter::ReadyToOutput, output, &PainterOutput::Process );
QObject::connect( &mapper, &PixelMapper::OnResize, &painter, &Painter::Resize );
QObject::connect( &mapper, &PixelMapper::OnResize, output, &PainterOutput::setCellSize );
QObject::connect( &settings, &AppSettings::fixturePathChanged, &mapper, &PixelMapperWithError::Reload );
QObject::connect( &settings, &AppSettings::portChanged, &receiver, &Receiver::Reconnect );
QObject::connect( &settings, &AppSettings::positionChanged, &painter, &Painter::RePosition );
if( !settings.fixturePath().isEmpty() )
mapper.Reload();
else
WARN("Pixel mapping empty, skip" );
LOG(1, "Listening on port %u with pixel-mapping file %s and orientation %s",
settings.port(), qPrintable(settings.fixturePath()), painter.Orientation() == Painter::Vertical ? "vertical" : "horizontal" );
QQuickWindow *window = qobject_cast<QQuickWindow *>(rootObject);
Q_ASSERT( window );
window->show();
const int res = app.exec();
settings.Save( settings_path + "app.data" );
return res;
}