本文整理汇总了C++中QCoreApplication::exec方法的典型用法代码示例。如果您正苦于以下问题:C++ QCoreApplication::exec方法的具体用法?C++ QCoreApplication::exec怎么用?C++ QCoreApplication::exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCoreApplication
的用法示例。
在下文中一共展示了QCoreApplication::exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: server
void runServer(QCoreApplication& app, const QString& portOrPath) {
using namespace qhttp::server;
QHttpServer server(&app);
// listening tcp port or Unix path
server.listen(portOrPath, [](QHttpRequest* req, QHttpResponse* res) {
res->setStatusCode(qhttp::ESTATUS_OK); // status 200
res->addHeader("connection", "close"); // it's the default header, this line can be omitted.
res->end("Hello World!\n"); // response body data
// when "connection: close", the req and res will be deleted automatically.
// optionally let the clients to shut down the server
if ( req->headers().keyHasValue("command", "quit") ) {
printf("a client sends a quit command.\nserver quits.\n");
QCoreApplication::quit();
return;
}
});
if ( !server.isListening() ) {
fprintf(stderr, "failed. can not listen at port %s!\n", qPrintable(portOrPath));
return;
}
app.exec(); // application's main event loop
}
示例3: Root
PugAPI::PugAPI(const std::string config)
{
m_root = new Root(new QQmlEngine);
// Qt::QueuedConnection is required, otherwise the slot will be called immediately, and
// since we're not in the event loop yet, quit() will have no effect
QObject::connect(m_root, SIGNAL(configLoaded()), &g_app, SLOT(quit()), Qt::QueuedConnection);
m_root->loadConfig(QString::fromStdString(config));
g_app.exec();
}
示例4: main
int main(int argc, char *argv[])
{
#ifdef _WIN32
timeBeginPeriod(1);
#endif
//initialize ressources (compiled images, etc.)
Q_INIT_RESOURCE(resources);
Core::resetCore();
//Start QApplication with or without GUI support.
bool useGui = true;
for(int i = 0; i < argc; ++i) {
if(QString(argv[i]) == "-nogui") {
useGui = false;
}
else if(QString(argv[i]) == "-gui") {
useGui = true;
}
}
QCoreApplication *app = 0;
if(useGui) {
app = new QApplication(argc, argv);
}
else {
app = new QCoreApplication(argc, argv);
}
OrcsModelOptimizerApplication *nerd =
new OrcsModelOptimizerApplication();
nerd->startApplication();
app->exec();
Core::getInstance()->waitForAllThreadsToComplete();
Core::resetCore();
delete app;
#ifdef _WIN32
timeEndPeriod(1);
#endif
return 0;
}
示例5: main
int main (int argc, char *argv[]) {
QCoreApplication a (argc, argv);
Nuria::HttpServer server;
server.root ()->connectSlot ("index", mySlot);
if (!server.listen (QHostAddress::Any, 3000)) {
nError() << "Failed to listen on port 3000.";
return 1;
}
nLog() << "Listening on all interfaces on port 3000.";
return a.exec ();
}
示例6: client
void runClient(QCoreApplication& app, const QString& portOrPath) {
using namespace qhttp::client;
QUrl url;
if ( portOrPath.toUShort() > 0 ) {
url.setScheme("http");
url.setHost("localhost");
url.setPort(portOrPath.toUShort());
} else {
url = QUrl::fromLocalFile(portOrPath);
}
QHttpClient client(&app);
bool success = client.request(qhttp::EHTTP_GET, url, [](QHttpResponse* res) {
// response handler, called when the HTTP headers of the response are ready
res->collectData(128);
// called when all data in HTTP response have been read.
res->onEnd([res]() {
// print the XML body of the response
puts("\n[incoming response:]");
puts(res->collectedData().constData());
puts("\n\n");
QCoreApplication::instance()->quit();
});
// just for fun! print headers:
puts("\n[Headers:]");
const qhttp::THeaderHash& hs = res->headers();
for ( auto cit = hs.constBegin(); cit != hs.constEnd(); cit++) {
printf("%s : %s\n", cit.key().constData(), cit.value().constData());
}
fflush(stdout);
});
if ( !success ) {
fprintf(stderr, "can not send a request to %s\n", qPrintable(url.toString()));
return;
}
app.exec();
}
示例7: main
int main(int argc, char** argv){
// Just so we know who we are.
QCoreApplication::setOrganizationName("Synthetic Intellect Institute");
QCoreApplication::setOrganizationDomain("thesii.org");
QCoreApplication::setApplicationName("SpeechControl");
// Lemme get a QCoreApplication for 200.
QCoreApplication* app = new QCoreApplication(argc,argv);
// Now, grab that instance one time!
Instance* instance = new Instance();
// Who's your momma?!
instance->setParent(app);
qDebug() << "D-Bus should be started.";
return app->exec();
}
示例8: main
int main(int argc, char *argv[])
{
QCoreApplication* app = new QCoreApplication(argc, argv);
/* brain contains a collection of things */
Brain* brain = new Brain();
/* start neuron IO */
UniverseClient* universeClient = setupIO(brain);
universeClient->initiateConnection();
/* preparation is done. let if flow! */
qDebug() << "started.";
return app->exec();
/* when we reach this, the program is finished. delete everything in reverse order. */
delete universeClient;
delete brain;
delete app;
}
示例9: main
int main (int argc, char *argv[])
{
QCoreApplication app (argc, argv);
CQmakeProjectParser parser( QDir::cleanPath (
QFileInfo (QDir::currentPath ())
.dir ()
.absoluteFilePath ("../libqmake/libqmake.pro")));
if (!parser.lastError ().isEmpty ())
{
qDebug() << "ERROR: " << parser.lastError ();
return 1;
}
qDebug() << "Project headers:";
foreach( QString header, parser.headers ()) qDebug() << "\t" << header;
qDebug() << "Project sources:";
foreach( QString src, parser.sources ()) qDebug() << "\t" << src;
return app.exec();
}
示例10: main
int main(int argc, char **argv)
{
QCoreApplication *qApp = new QCoreApplication(argc, argv);
NXClientLib lib(qApp);
lib.invokeNXSSH("default" ,argv[1], true);
lib.setUsername(argv[2]);
lib.setPassword(argv[3]);
lib.setResolution(640,480);
lib.setDepth(24);
lib.setRender(true);
NXSessionData session;
// HARDCODED TEST CASE
session.sessionName = "TEST";
session.sessionType = "unix-kde";
session.cache = 8;
session.images = 32;
session.linkType = "adsl";
session.render = true;
session.backingstore = "when_requested";
session.imageCompressionMethod = 2;
// session.imageCompressionLevel;
session.geometry = "800x600+0+0";
session.keyboard = "defkeymap";
session.kbtype = "pc102/defkeymap";
session.media = false;
session.agentServer = "";
session.agentUser = "";
session.agentPass = "";
session.cups = 0;
session.suspended = false;
lib.setSession(&session);
return qApp->exec();
}
示例11: main
//.........这里部分代码省略.........
// Init download engines (let them load settings)
initSettingsDefaults(m_strSettingsPath);
if(m_bStartGUI)
initSettingsPages();
#ifdef WITH_JPLUGINS
if (!m_bDisableJava)
{
new JVM(m_bJavaForceSearch);
if (JVM::JVMAvailable())
{
JavaDownload::globalInit();
JavaExtractor::globalInit();
JavaUpload::globalInit();
FileSharingSearch::globalInit();
}
}
#endif
installSignalHandler();
initTransferClasses();
loadPlugins();
runEngines();
qRegisterMetaType<QString*>("QString*");
qRegisterMetaType<QByteArray*>("QByteArray*");
qRegisterMetaType<Transfer*>("Transfer*");
qRegisterMetaType<Transfer::TransferList>("Transfer::TransferList");
Queue::loadQueues();
initAppTools();
// force singleton creation
TransferFactory::instance();
g_qmgr = new QueueMgr;
#ifdef WITH_WEBINTERFACE
XmlRpcService::globalInit();
new HttpService;
#endif
if(m_bStartGUI)
g_wndMain = new MainWindow(m_bStartHidden);
else
qDebug() << "FatRat is up and running now";
new RssFetcher;
initDbus();
//testNotif();
if(!arg.isEmpty() && m_bStartGUI)
g_wndMain->addTransfer(arg);
#ifdef WITH_JABBER
new JabberService;
#endif
new Scheduler;
if(m_bStartGUI)
QApplication::setQuitOnLastWindowClosed(false);
rval = app->exec();
#ifdef WITH_JABBER
delete JabberService::instance();
#endif
#ifdef WITH_WEBINTERFACE
delete HttpService::instance();
#endif
delete RssFetcher::instance();
delete Scheduler::instance();
delete g_wndMain;
g_qmgr->exit();
Queue::stopQueues();
Queue::saveQueues();
Queue::unloadQueues();
runEngines(false);
#ifdef WITH_JPLUGINS
if (!m_bDisableJava && JVM::JVMAvailable())
{
JavaExtractor::globalExit();
JavaDownload::globalExit();
FileSharingSearch::globalExit();
}
#endif
delete g_qmgr;
exitSettings();
delete app;
return rval;
}
示例12: main
int main(int argc, char *argv[])
{
#ifdef _WIN32
timeBeginPeriod(1);
#endif
#ifdef Q_WS_X11
XInitThreads();
#endif
//initialize ressources (compiled images, etc.)
Q_INIT_RESOURCE(resources);
Core::resetCore();
//Start QApplication with or without GUI support.
bool useGui = true;
for(int i = 0; i < argc; ++i) {
if(QString(argv[i]) == "-nogui") {
useGui = false;
}
else if(QString(argv[i]) == "-gui") {
useGui = true;
}
}
QCoreApplication *app = 0;
if(useGui) {
app = new QApplication(argc, argv);
}
else {
app = new QCoreApplication(argc, argv);
}
NerdNeuroEvoApplication *nerd = new NerdNeuroEvoApplication();
nerd->prepareApplication();
nerd->startApplication();
app->exec();
Core::getInstance()->waitForAllThreadsToComplete();
//bool hasPlugins = (Core::getInstance()->getPlugInManager()->getNumberOfLoadedPlugIns() > 0);
Core::resetCore();
delete app;
#ifdef _WIN32
timeEndPeriod(1);
#endif
Q_CLEANUP_RESOURCE(resources);
//TODO This is to circumvent a problem with hanging applications when a plugin is loaded.
//The reason for the hanging could not be found and solved yet!
//Update: Seems to be fixed in QT
//if(hasPlugins) {
// abort();
//}
return 0;
}
示例13: main
//.........这里部分代码省略.........
#if QT_VERSION >= 0x050000
// setting all buttons to the same roles allows us
// to have a custom layout
discard = mb.addButton( MainWindow::tr( "Discard" ),
QMessageBox::AcceptRole );
ignore = mb.addButton( MainWindow::tr( "Ignore" ),
QMessageBox::AcceptRole );
recover = mb.addButton( MainWindow::tr( "Recover" ),
QMessageBox::AcceptRole );
# else
// in qt4 the button order is reversed
recover = mb.addButton( MainWindow::tr( "Recover" ),
QMessageBox::AcceptRole );
ignore = mb.addButton( MainWindow::tr( "Ignore" ),
QMessageBox::AcceptRole );
discard = mb.addButton( MainWindow::tr( "Discard" ),
QMessageBox::AcceptRole );
#endif
// have a hidden exit button
exit = mb.addButton( "", QMessageBox::RejectRole);
exit->setVisible(false);
// set icons
recover->setIcon( embed::getIconPixmap( "recover" ) );
discard->setIcon( embed::getIconPixmap( "discard" ) );
ignore->setIcon( embed::getIconPixmap( "ignore" ) );
mb.setDefaultButton( recover );
mb.setEscapeButton( exit );
mb.exec();
if( mb.clickedButton() == discard )
{
gui->mainWindow()->sessionCleanup();
}
else if( mb.clickedButton() == recover ) // Recover
{
fileToLoad = recoveryFile;
gui->mainWindow()->setSession( MainWindow::SessionState::Recover );
}
else if( mb.clickedButton() == ignore )
{
if( autoSaveEnabled )
{
gui->mainWindow()->setSession( MainWindow::SessionState::Limited );
}
}
else // Exit
{
return 0;
}
}
// first show the Main Window and then try to load given file
// [Settel] workaround: showMaximized() doesn't work with
// FVWM2 unless the window is already visible -> show() first
gui->mainWindow()->show();
if( fullscreen )
{
gui->mainWindow()->showMaximized();
}
示例14: main
//.........这里部分代码省略.........
splashScreen.show();
splashScreen.showMessage( MainWindow::tr( "Version %1" ).arg( LMMS_VERSION ),
Qt::AlignRight | Qt::AlignBottom, Qt::white );
qApp->processEvents();
// init central engine which handles all components of LMMS
engine::init();
splashScreen.hide();
// re-intialize RNG - shared libraries might have srand() or
// srandom() calls in their init procedure
srand( getpid() + time( 0 ) );
// recover a file?
QString recoveryFile = QDir(configManager::inst()->workingDir()).absoluteFilePath("recover.dataFile");
if( QFileInfo(recoveryFile).exists() &&
QMessageBox::question( engine::mainWindow(), MainWindow::tr( "Project recovery" ),
MainWindow::tr( "It looks like the last session did not end properly. "
"Do you want to recover the project of this session?" ),
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
{
file_to_load = recoveryFile;
}
// we try to load given file
if( !file_to_load.isEmpty() )
{
engine::mainWindow()->show();
if( fullscreen )
{
engine::mainWindow()->showMaximized();
}
if( file_to_load == recoveryFile )
{
engine::getSong()->createNewProjectFromTemplate( file_to_load );
}
else
{
engine::getSong()->loadProject( file_to_load );
}
}
else if( !file_to_import.isEmpty() )
{
ImportFilter::import( file_to_import, engine::getSong() );
if( exit_after_import )
{
return 0;
}
engine::mainWindow()->show();
if( fullscreen )
{
engine::mainWindow()->showMaximized();
}
}
else
{
engine::getSong()->createNewProject();
// [Settel] workaround: showMaximized() doesn't work with
// FVWM2 unless the window is already visible -> show() first
engine::mainWindow()->show();
if( fullscreen )
{
engine::mainWindow()->showMaximized();
}
}
}
else
{
// we're going to render our song
engine::init( false );
printf( "loading project...\n" );
engine::getSong()->loadProject( file_to_load );
printf( "done\n" );
// create renderer
ProjectRenderer * r = new ProjectRenderer( qs, os, eff,
render_out +
QString( ( eff ==
ProjectRenderer::WaveFile ) ?
"wav" : "ogg" ) );
QCoreApplication::instance()->connect( r,
SIGNAL( finished() ), SLOT( quit() ) );
// timer for progress-updates
QTimer * t = new QTimer( r );
r->connect( t, SIGNAL( timeout() ),
SLOT( updateConsoleProgress() ) );
t->start( 200 );
// start now!
r->startProcessing();
}
const int ret = app->exec();
delete app;
return( ret );
}
示例15: main
int main(int argc, char *argv[])
{
#ifdef WITH_IMAGEMAGICK
Magick::InitializeMagick(*argv);
#endif
QCoreApplication *a = (argc == 1) ? new QApplication(argc, argv) : new QCoreApplication(argc, argv);
if(a)
{
/* we need nice getDataHome */
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
QCoreApplication::setApplicationName("luckygps");
QCoreApplication::setOrganizationName(".");
#endif
QLocale locale = QLocale::system();
QString locale_name = locale.name();
QTranslator translator;
/* Detect if luckyGPS is executed in "local mode" (no installation) */
int local = 0;
QDir dir(QCoreApplication::applicationDirPath());
QFileInfoList fileList = dir.entryInfoList(QStringList("luckygps_*.qm"), QDir::AllEntries | QDir::NoDot | QDir::NoDotDot);
if(fileList.length() > 0)
local = 1;
#if defined(Q_OS_LINUX)
translator.load(QString("luckygps_") + locale_name, "/usr/share/luckygps");
#else
translator.load(QString("luckygps_") + locale_name, getDataHome(local));
#endif
a->installTranslator(&translator);
setlocale(LC_NUMERIC, "C");
if(argc == 1)
{
MainWindow w(0, local);
w.show();
a->exec();
}
#ifdef WITH_ROUTING
else
{
/* check if 1 argument is given */
if(argc > 3)
{
printf("\nUsage: luckygps FILE.osm.pbf [SETTINGS.spp]\n");
}
else
{
QString settingsFile;
if(argc == 2)
settingsFile = ":/data/motorcar.spp";
else
settingsFile = QString(argv[2]);
/* import osm file into routing database */
if(importOsmPbf(a, argv[1], settingsFile, local))
qWarning() << "Import successfully.";
else
qWarning() << "Import failed.";
}
}
#endif
delete a;
}
return true;
}