本文整理汇总了C++中QCoreApplication类的典型用法代码示例。如果您正苦于以下问题:C++ QCoreApplication类的具体用法?C++ QCoreApplication怎么用?C++ QCoreApplication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QCoreApplication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[])
{
// construct core app
QCoreApplication app (argc, argv);
// get arguments
QString encoding = app.arguments().at(1);
QString inFile = app.arguments().at(2);
QString outFile = app.arguments().at(3);
Kate::TextBuffer buffer (0);
// set codec
buffer.setFallbackTextCodec (QTextCodec::codecForName ("ISO 8859-15"));
buffer.setTextCodec (QTextCodec::codecForName (encoding.toLatin1()));
// switch to Mac EOL, this will test eol detection, as files are normal unix or dos
buffer.setEndOfLineMode (Kate::TextBuffer::eolMac);
// load file
bool encodingErrors = false;
bool tooLongLines = false;
if (!buffer.load (inFile, encodingErrors, tooLongLines) || encodingErrors)
return 1;
// save file
if (!buffer.save (outFile))
return 1;
return 0;
}
示例2: initialize
void QGBSettings::initialize(const QCoreApplication & appli){
appli.setOrganizationName("Satellite");
appli.setOrganizationDomain("satellite.epfl.ch");
appli.setApplicationName("QGoldenBook");
d_instance = new QGBSettings();
}
示例3: toolOnSetup
void grabUVContext::toolOnSetup( MEvent &event )
{
MPxTexContext::toolOnSetup( event );
QCoreApplication *app = qApp;
app->installEventFilter(this);
}
示例4: initialize
void Global::initialize()
{
// stop init process and exit if the class was allready initialized
if(Global::init) {
return;
}
// simplefy application instance
QCoreApplication* app = QApplication::instance();
// init settings
QString strConfigFile = QFileInfo(app->applicationFilePath()).baseName() + ".ini";
if(!QFile::exists(strConfigFile)) {
qFatal("Cannot find Config file:\r\n%s", qPrintable(strConfigFile));
}
Global::settings = new QSettings(strConfigFile, QSettings::IniFormat);
Global::strServerHostname = Global::settings->value("server/hostname", Global::strServerHostname).toString();
Global::intServerPort = Global::settings->value("server/port", Global::intServerPort).toUInt();
Global::strSessionName = Global::settings->value("session/name", Global::strSessionName).toString();
// init socket
Global::socketServer = new QTcpSocket(app);
// init EleaphRpc handler
Global::eleaphRpc = new EleaphRpc(app);
Global::eleaphRpc->addDevice(Global::socketServer, IEleaph::NeverForgetDevice);
// class was successfull initialized!
Global::init = true;
}
示例5: loadTranslations
void loadTranslations( QCoreApplication &app, QTranslator &translator )
{
const QString lang = QLocale::system().name();
QString code;
int index = lang.indexOf ( '_' );
if ( lang == "C" ) {
code = "en";
}
else if ( index != -1 ) {
code = lang.left ( index );
}
else {
index = lang.indexOf ( '@' );
if ( index != -1 )
code = lang.left ( index );
else
code = lang;
}
QString const i18nDir = "/usr/share/marble/translations";
QString const relativeDir = app.applicationDirPath() + "/translations";
foreach( const QString &path, QStringList() << i18nDir << relativeDir << QDir::currentPath() ) {
foreach( const QString &lang, QStringList() << lang << code ) {
QFileInfo translations = QFileInfo( path + "/routing-instructions_" + lang + ".qm" );
if ( translations.exists() && translator.load( translations.absoluteFilePath() ) ) {
app.installTranslator( &translator );
return;
}
}
}
}
示例6: initialize
void Global::initialize()
{
// stop init process and exit if the class was allready initialized
if(Global::init) {
return;
}
// simplefy application instance
QCoreApplication* app = QCoreApplication::instance();
/// init settings
QString strConfigFile = QFileInfo(app->applicationFilePath()).baseName() + ".ini";
if(!QFile::exists(strConfigFile)) {
qFatal("Cannot find Config file:\r\n%s", qPrintable(strConfigFile));
}
Global::settings = new QSettings(strConfigFile, QSettings::IniFormat);
/// init database helper
QSqlDatabase database = QSqlDatabase::addDatabase(Global::getConfigValue("database/driver").toString(), "sqm");
database.setDatabaseName(Global::getConfigValue("database/name", "").toString());
database.setHostName(Global::getConfigValue("database/hostname", "").toString());
database.setPort(Global::getConfigValue("database/port", 0).toInt());
database.setUserName(Global::getConfigValue("database/username", "").toString());
database.setPassword(Global::getConfigValue("database/password", "").toString());
database.setConnectOptions(Global::getConfigValue("database/connectoptions", "").toString());
if(database.open()) {
printf("Datenbank Verbindung erfolgreich!");
} else {
qFatal("Datenbank Verbindung NICHT erfolgreich!");
}
Global::databaseHelper = new DatabaseHelper("sqm");
// class was successfull initialized!
Global::init = true;
}
示例7: listAppletInfoForUrl
KPluginInfo::List PluginLoader::listAppletInfoForUrl(const QUrl &url)
{
QString parentApp;
QCoreApplication *app = QCoreApplication::instance();
if (app) {
parentApp = app->applicationName();
}
auto filter = [&parentApp](const KPluginMetaData &md) -> bool
{
const QString pa = md.value(QStringLiteral("X-KDE-ParentApp"));
return (pa.isEmpty() || pa == parentApp) && !md.value(QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty();
};
KPluginInfo::List allApplets = KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter).toVector());
KPluginInfo::List filtered;
foreach (const KPluginInfo &info, allApplets) {
QStringList urlPatterns = info.property("X-Plasma-DropUrlPatterns").toStringList();
foreach (const QString &glob, urlPatterns) {
QRegExp rx(glob);
rx.setPatternSyntax(QRegExp::Wildcard);
if (rx.exactMatch(url.toString())) {
#ifndef NDEBUG
// qCDebug(LOG_PLASMA) << info.name() << "matches" << glob << url;
#endif
filtered << info;
}
}
示例8: main
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(resources);
Core::resetCore();
//Start QApplication with or without GUI support.
bool useGui = false;
for(int i = 0; i < argc; ++i) {
if(QString(argv[i]) == "-gui") {
useGui = true;
}
}
QCoreApplication *app = 0;
if(useGui) {
app = new QApplication(argc, argv);
}
else {
app = new QCoreApplication(argc, argv);
}
ASeriesClientApplication *nerd = new ASeriesClientApplication();
nerd->startApplication();
app->exec();
Core::getInstance()->waitForAllThreadsToComplete();
Core::resetCore();
delete app;
return 0;
}
示例9: mainContext
QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context)
: mainContext(context)
{
#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32
if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) {
static QBasicMutex mutex;
QMutexLocker locker(&mutex);
if (!g_thread_supported())
g_thread_init(NULL);
}
#endif
if (mainContext) {
g_main_context_ref(mainContext);
} else {
QCoreApplication *app = QCoreApplication::instance();
if (app && QThread::currentThread() == app->thread()) {
mainContext = g_main_context_default();
g_main_context_ref(mainContext);
} else {
mainContext = g_main_context_new();
}
}
#if GLIB_CHECK_VERSION (2, 22, 0)
g_main_context_push_thread_default (mainContext);
#endif
// setup post event source
postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs,
sizeof(GPostEventSource)));
postEventSource->serialNumber.store(1);
postEventSource->d = this;
g_source_set_can_recurse(&postEventSource->source, true);
g_source_attach(&postEventSource->source, mainContext);
// setup socketNotifierSource
socketNotifierSource =
reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs,
sizeof(GSocketNotifierSource)));
(void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>();
g_source_set_can_recurse(&socketNotifierSource->source, true);
g_source_attach(&socketNotifierSource->source, mainContext);
// setup normal and idle timer sources
timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs,
sizeof(GTimerSource)));
(void) new (&timerSource->timerList) QTimerInfoList();
timerSource->processEventsFlags = QEventLoop::AllEvents;
timerSource->runWithIdlePriority = false;
g_source_set_can_recurse(&timerSource->source, true);
g_source_attach(&timerSource->source, mainContext);
idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs,
sizeof(GIdleTimerSource)));
idleTimerSource->timerSource = timerSource;
g_source_set_can_recurse(&idleTimerSource->source, true);
g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE);
g_source_attach(&idleTimerSource->source, mainContext);
}
示例10: main
int main(int argc, char *argv[]) {
QCoreApplication app (argc, argv);
if (app.arguments().size() != 2) {
qCritical("You have to specify the file containing the json code");
exit (1);
}
QString filename = app.arguments()[1];
if (!QFile::exists ( filename )) {
qCritical ("The file you specified doesn't exist!");
exit (1);
}
Parser driver;
bool ok;
QFile file (filename);
QVariant data = driver.parse (&file, &ok);
if (!ok) {
qCritical("%s:%i - Error: %s", filename.toLatin1().data(), driver.errorLine(), qPrintable(driver.errorString()));
exit (1);
}
else {
qDebug() << "json object successfully converted to:";
qDebug() << data;
}
qDebug() << "JOB DONE, BYE";
return 0;
}
示例11: toolOffCleanup
void grabUVContext::toolOffCleanup()
{
QCoreApplication *app = qApp;
app->removeEventFilter(this);
MPxTexContext::toolOffCleanup();
}
示例12: qtnStartInplaceEdit
bool qtnStartInplaceEdit(QWidget* editor)
{
if (!editor)
return false;
if (g_inplaceEditor)
{
Q_ASSERT(false);
qtnStopInplaceEdit();
}
QCoreApplication* app = QCoreApplication::instance();
if (!app)
{
Q_ASSERT(false);
return false;
}
g_inplaceEditor = editor;
g_inplaceEditorHandler = new QtnInplaceEditorHandler();
// move focus to editor
if (QApplication::focusWidget() != g_inplaceEditor->focusWidget())
g_inplaceEditor->setFocus();
// connect to editor destroyed signal
QObject::connect( g_inplaceEditor, &QObject::destroyed
, g_inplaceEditorHandler, &QtnInplaceEditorHandler::OnEditorDestroyed);
// install application event filter
app->installEventFilter(g_inplaceEditorHandler);
return true;
}
示例13: locker
QApplicationActivityObserver * QApplicationActivityObserver::instance()
{
static QMutex mymutex;
static QScopedPointer<QApplicationActivityObserver> instance;
QMutexLocker locker(&mymutex);
// Creating instance
if (instance.isNull())
{
instance.reset(new QApplicationActivityObserver());
}
// Installing event filter
static bool installed_filter = false;
if (!installed_filter)
{
QCoreApplication * app = QCoreApplication::instance();
if (app)
{
app->installEventFilter(instance.data());
installed_filter = true;
qDebug()<<__FUNCTION__<<"Successfully installed event filter.";
}
else
{
qWarning()<<__FUNCTION__<<"installing event filter failed because QCoreApplication instance doesn't exist, will try later.";
}
}
return instance.data();
}
示例14: on_about
void MainWindow::on_about()
{
QCoreApplication * app = QCoreApplication::instance();
QMessageBox::about(this, app->applicationName(), app->applicationName()
+ ": example of Qt using marnav\n\nVersion: " + app->applicationVersion()
+ "\n\nSee file: LICENSE");
}
示例15: exit
/*!
Enters the main event loop and waits until exit() is called.
Returns the value that was passed to exit().
If \a flags are specified, only events of the types allowed by
the \a flags will be processed.
It is necessary to call this function to start event handling. The
main event loop receives events from the window system and
dispatches these to the application widgets.
Generally speaking, no user interaction can take place before
calling exec(). As a special case, modal widgets like QMessageBox
can be used before calling exec(), because modal widgets
use their own local event loop.
To make your application perform idle processing (i.e. executing a
special function whenever there are no pending events), use a
QTimer with 0 timeout. More sophisticated idle processing schemes
can be achieved using processEvents().
\sa QApplication::quit(), exit(), processEvents()
*/
int QEventLoop::exec(ProcessEventsFlags flags)
{
Q_D(QEventLoop);
//we need to protect from race condition with QThread::exit
QMutexLocker locker(&static_cast<QThreadPrivate *>(QObjectPrivate::get(d->threadData->thread))->mutex);
if (d->threadData->quitNow)
return -1;
if (d->inExec) {
qWarning("QEventLoop::exec: instance %p has already called exec()", this);
return -1;
}
d->inExec = true;
d->exit = false;
++d->threadData->loopLevel;
d->threadData->eventLoops.push(this);
locker.unlock();
// remove posted quit events when entering a new event loop
QCoreApplication *app = QCoreApplication::instance();
if (app && app->thread() == thread())
QCoreApplication::removePostedEvents(app, QEvent::Quit);
#if defined(QT_NO_EXCEPTIONS)
while (!d->exit)
processEvents(flags | WaitForMoreEvents | EventLoopExec);
#else
try {
while (!d->exit)
processEvents(flags | WaitForMoreEvents | EventLoopExec);
} catch (...) {
qWarning("Qt has caught an exception thrown from an event handler. Throwing\n"
"exceptions from an event handler is not supported in Qt. You must\n"
"reimplement QApplication::notify() and catch all exceptions there.\n");
// copied from below
locker.relock();
QEventLoop *eventLoop = d->threadData->eventLoops.pop();
Q_ASSERT_X(eventLoop == this, "QEventLoop::exec()", "internal error");
Q_UNUSED(eventLoop); // --release warning
d->inExec = false;
--d->threadData->loopLevel;
throw;
}
#endif
// copied above
locker.relock();
QEventLoop *eventLoop = d->threadData->eventLoops.pop();
Q_ASSERT_X(eventLoop == this, "QEventLoop::exec()", "internal error");
Q_UNUSED(eventLoop); // --release warning
d->inExec = false;
--d->threadData->loopLevel;
return d->returnCode;
}