本文整理汇总了C++中QApplication::applicationDirPath方法的典型用法代码示例。如果您正苦于以下问题:C++ QApplication::applicationDirPath方法的具体用法?C++ QApplication::applicationDirPath怎么用?C++ QApplication::applicationDirPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QApplication
的用法示例。
在下文中一共展示了QApplication::applicationDirPath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_constants
/**
* @brief Load program constants from constants.xml.
* @return true on success, false on failure
*/
static bool load_constants(QApplication& app)
{
#ifdef DATA_PATH
QString app_path = QString(DATA_PATH);
(void)app; // eliminate "variable not used" warning
#else
QString app_path = app.applicationDirPath();
#endif
QString constant_xml_filename = QDir(app_path).absoluteFilePath("constants.xml");
// open constant xml file
QFile constant_xml(constant_xml_filename);
constant_xml.open(QIODevice::ReadOnly);
if (!constant_xml.isOpen()) {
qCritical() << "Failed to read file: " << constant_xml_filename;
QMessageBox::critical(0, "QWinFF",
QString("Cannot load %1. The program will exit now.")
.arg(constant_xml_filename));
return false;
}
qDebug() << "Reading file: " << constant_xml_filename;
// parse the xml file
if (!Constants::readFile(constant_xml)) {
QMessageBox::critical(0, "QWinFF",
QString("%1 contains error(s). "
"Reinstall the application may solve the problem.")
.arg(constant_xml_filename));
return false;
}
return true;
}
示例2: main
int main ( int argc, char *argv[] )
{
QApplication app ( argc, argv );
QString locale;
{
QSettings settings ( "RolTram", "RS" );
settings.beginGroup ( "Locale" );
if ( settings.contains ( "Locale" ) )
locale = settings.value ( "Locale" ).toString();
else
locale = QLocale::system().name();
}
QTranslator translator;
if (( locale != "pt_BR" ) && ( locale != "ptBR" ) && ( locale != "C" ))
{
QString localeFileName = QString ( "rs_" ) + locale + ".qm";
QStringList searchPaths;
searchPaths << QDir::toNativeSeparators ( app.applicationDirPath() + QDir::separator() )
#ifdef __unix__
<< "../share/" << "/usr/share/rs/" << "/usr/local/share/rs/"
<< "/usr/share/" << "/usr/local/share/";
#else
<< "../share/" << "C:/usr/share/rs/" << "C:/usr/local/share/rs/"
<< "C:/usr/share/" << "C:/usr/local/share/";
示例3: initialize
void initialize(const QApplication& app)
{
const auto appdir = app.applicationDirPath();
initialize_value(appdir, "config/is_authorized", subara::config::is_authorized);
initialize_value(appdir, "config/oauth_token", subara::config::oauth_token);
initialize_value(appdir, "config/oauth_token_secret", subara::config::oauth_token_secret);
}
示例4: init
// 初始化
void MyApp::init(QApplication &app)
{
m_strAppPath = app.applicationDirPath() + "/";
#ifdef Q_OS_UNIX
if (!m_strAppPath.startsWith("/")) {
myDebug("m_strAppPath no start with /" << m_strAppPath) ;
m_strAppPath = "/" + m_strAppPath;
}
#endif
m_strDataPath = m_strAppPath + "data/";
m_strLogPath = m_strDataPath + "log";
m_strTestPath = m_strDataPath + "test/";
m_strDownloadPath = m_strAppPath + "download/";
m_strScreenShotPath = m_strDataPath + "screen_shot/";
m_strWavPath = m_strDataPath + "wav_normal/";
m_strRecordPath = m_strDataPath + "record/";
m_strDbPath = m_strDataPath + "database/";
m_strBackupPath = m_strDataPath + "backup/";
m_strConfPath = m_strDataPath + "conf/";
m_strIniFile = m_strConfPath + "config.ini";
// 检查目录
checkDirs();
// 创建配置文件
creatorSettingFile();
// 读取设备编号
m_strDevId = getSettingKeyValue("SysConfig", "DeviceId", "59909200001").toString();
// 数据上传服务器配置
m_strDataServerAddr = getSettingKeyValue("DataServer", "IpAddr", "222.180.250.162").toString();
m_nDataServerPort = getSettingKeyValue("DataServer", "Port", 5100).toInt();
// 系统升级配置
m_strUpServerUrl = getSettingKeyValue("Version", "AppUrl",
"http://121.40.121.132:9191/apps/vict_app").toString();
m_strCheckVersion = getSettingKeyValue("Version", "VerUrl",
"http://121.40.121.132:9191/vict_version.php").toString();
m_strAppName = getSettingKeyValue("Version", "AppName", "vict_app").toString();
// 音量控制
m_nSysVolume = getSettingKeyValue("SysConfig", "SysVolume", 127).toInt();
m_nRecVolume = getSettingKeyValue("SysConfig", "RecVolume", 85).toInt();
// SMTP
m_strSmtpAddr = getSettingKeyValue("Server", "SmtpAddr", "220.181.12.12").toString();
// 读取用户配置
m_strMsgServer = getSettingKeyValue("Server", "MsgServer", "183.230.8.172").toString();
m_nUdpRoomPort = getSettingKeyValue("Server", "UdpRoom", 43434).toInt();
m_nTcpMsgPort = getSettingKeyValue("Server", "MsgProt", 60001).toInt();
m_nTcpFilePort = getSettingKeyValue("Server", "FilePort", 60001).toInt();
m_nUserId = getSettingKeyValue("MsgUser", "Id", 101).toInt();
m_strPwd = getSettingKeyValue("MsgUser", "Passwd", "123").toString();
}
示例5: main
int main (int argc, char *argv[]) {
QApplication app (argc, argv);
QStringList args = app.arguments ();
if (!args.isEmpty ()) args.pop_front (); // The command itself
qputenv ("DESKTOP_STARTUP_ID", qgetenv ("STARTUP_ID_COPY")); // for startup notifications (set via rkward.desktop)
qputenv ("STARTUP_ID_COPY", "");
// Parse arguments that need handling in the wrapper
bool usage = false;
QStringList debugger_args;
QStringList file_args;
bool reuse = false;
bool warn_external = true;
QString r_exe_arg;
int debug_level = 2;
for (int i=0; i < args.size (); ++i) {
if (args[i] == "--debugger") {
args.removeAt (i);
while (i < args.size ()) {
QString arg = args.takeAt (i);
if (arg == "--") break;
debugger_args.append (arg);
}
if (debugger_args.isEmpty ()) usage = true;
} else if (args[i] == "--r-executable") {
if ((i+1) < args.size ()) {
r_exe_arg = args.takeAt (i + 1);
} else usage = true;
args.removeAt (i);
--i;
} else if (args[i] == "--debug-level") {
if ((i+1) < args.size ()) {
debug_level = args[i+1].toInt ();
}
} else if (args[i] == "--reuse") {
reuse = true;
} else if (args[i] == "--nowarn-external") {
warn_external = false;
} else if (args[i].startsWith ("--")) {
// all RKWard and KDE options (other than --reuse) are of the for --option <value>. So skip over the <value>
i++;
} else {
QUrl url (args[i]);
if (url.isRelative ()) {
file_args.append (QDir::current ().absoluteFilePath (url.toLocalFile ()));
} else {
file_args.append (args[i]);
}
}
}
if (reuse) {
if (!QDBusConnection::sessionBus ().isConnected ()) {
if (debug_level > 2) qDebug ("Could not connect to session dbus");
} else {
QDBusInterface iface (RKDBUS_SERVICENAME, "/", "", QDBusConnection::sessionBus ());
if (iface.isValid ()) {
QDBusReply<void> reply = iface.call ("openAnyUrl", file_args, warn_external);
if (!reply.isValid ()) {
if (debug_level > 2) qDebug ("Error while placing dbus call: %s", qPrintable (reply.error ().message ()));
return 1;
}
return 0;
}
}
}
// MacOS may need some path adjustments, first
#ifdef Q_WS_MAC
QString oldpath = qgetenv ("PATH");
if (!oldpath.contains (INSTALL_PATH)) {
//ensure that PATH is set to include what we deliver with the bundle
qputenv ("PATH", QString ("%1/bin:%1/sbin:%2").arg (INSTALL_PATH).arg (oldpath).toLocal8Bit ());
if (debug_level > 3) qDebug ("Adjusting system path to %s", qPrintable (qgetenv ("PATH")));
}
// ensure that RKWard finds its own packages
qputenv ("R_LIBS", R_LIBS);
QProcess::execute ("launchctl", QStringList () << "load" << "-w" << INSTALL_PATH "/Library/LaunchAgents/org.freedesktop.dbus-session.plist");
#endif
// Locate KDE and RKWard installations
QString kde4_config_exe = findExeAtPath ("kde4-config", QDir::currentPath ());
if (kde4_config_exe.isNull ()) kde4_config_exe = findExeAtPath ("kde4-config", app.applicationDirPath ());
if (kde4_config_exe.isNull ()) kde4_config_exe = findExeAtPath ("kde4-config", QDir (app.applicationDirPath ()).filePath ("KDE/bin"));
if (kde4_config_exe.isNull ()) {
#ifdef Q_WS_WIN
QStringList syspath = QString (qgetenv ("PATH")).split (';');
#else
QStringList syspath = QString (qgetenv ("PATH")).split (':');
#endif
for (int i = 0; i < syspath.size (); ++i) {
kde4_config_exe = findExeAtPath ("kde4-config", syspath[i]);
if (!kde4_config_exe.isNull ()) break;
}
}
if (kde4_config_exe.isNull ()) {
QMessageBox::critical (0, "Could not find KDE installation", "The KDE installation could not be found (kde4-config). When moving / copying RKWard, make sure to copy the whole application folder, or create a shorcut / link, instead.");
exit (1);
//.........这里部分代码省略.........