mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
强制初始工作目录为程序所在目录。
macOS/Windows/Linux都是这样。
This commit is contained in:
parent
d449afc093
commit
6b26486d86
@ -5,12 +5,14 @@
|
||||
#include "qqtgui.h"
|
||||
#include "qqtwindow.h"
|
||||
|
||||
#include "qqtapplication.h"
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QQtApplication::setHighDpiScaling();
|
||||
QQtApplication a ( argc, argv );
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
|
||||
QApplication::setAttribute ( Qt::AA_EnableHighDpiScaling, true );
|
||||
QApplication::setAttribute ( Qt::AA_UseHighDpiPixmaps, true );
|
||||
#endif
|
||||
|
||||
QQTApp a ( argc, argv );
|
||||
|
||||
QQTWindow w;
|
||||
w.show();
|
||||
|
@ -45,11 +45,12 @@ QQtApplication::QQtApplication ( int& argc, char** argv ) :
|
||||
qqtApp = this;
|
||||
|
||||
/*这里是个方便,因为配置文件默认在运行目录.*/
|
||||
/*如果用户的运行程序,希望运行目录在当前执行的目录下,这个代码移除,默认就是在调用目录工作.*/
|
||||
/*如果用户的运行程序,希望运行目录在当前执行的目录下,在自己的程序中改变下即可。*/
|
||||
/*在继承类里做这个工作,工作量实在是太大了,所以,我在这里做的.*/
|
||||
#if defined (__DARWIN__) || defined (__EMBEDDED_LINUX__)
|
||||
//#if defined (__DARWIN__) || defined (__EMBEDDED_LINUX__)
|
||||
startWorkRoot = QDir::currentPath();
|
||||
QDir::setCurrent ( qApp->applicationDirPath() );
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
qDebug() << tr ( "QQt Application Framework Software" );
|
||||
qDebug() << tr ( "Copyright (C) 2017 Tianduanrui. All rights reserved." );
|
||||
@ -169,6 +170,21 @@ void QQtApplication::setHighDpiScaling ( bool open )
|
||||
#endif
|
||||
}
|
||||
|
||||
void QQtApplication::setWorkRoot ( const QString workroot )
|
||||
{
|
||||
QDir::setCurrent ( workroot );
|
||||
}
|
||||
|
||||
const QString QQtApplication::getWorkRoot()
|
||||
{
|
||||
return QDir::currentPath();
|
||||
}
|
||||
|
||||
const QString QQtApplication::getStartingWorkRoot()
|
||||
{
|
||||
return startWorkRoot;
|
||||
}
|
||||
|
||||
void QQtApplication::slotUPanAutoRun ( int status )
|
||||
{
|
||||
if ( !bUPanAutoRun )
|
||||
|
@ -38,6 +38,17 @@ public:
|
||||
//>=5.6.0,建议5.7.1以后开始使用。
|
||||
static void setHighDpiScaling ( bool open = true );
|
||||
|
||||
//设置工作目录
|
||||
void setWorkRoot ( const QString workroot );
|
||||
|
||||
//获取工作目录 总是跟随用户设置改变
|
||||
const QString getWorkRoot();
|
||||
|
||||
//QQtApplication把启动目录强制切换到了应用程序所在目录,如果用户需要更改回去,那么自己切换到这个目录即可。
|
||||
//获取启动时目录 $(pwd)或者%CD%
|
||||
//这个值是固定不变的。
|
||||
const QString getStartingWorkRoot();
|
||||
|
||||
//这两个函数和MFC架构里的那两个函数一样的功能,但是Qt提供了main函数里的更好的窗口启动方法,所以,这里不实现。
|
||||
virtual int initInstance() { return 0; }
|
||||
virtual int unInitInstance() { return 0; }
|
||||
@ -56,6 +67,9 @@ private:
|
||||
|
||||
private:
|
||||
QTranslator* language;
|
||||
|
||||
private:
|
||||
QString startWorkRoot;
|
||||
};
|
||||
|
||||
extern QQtApplication* qqtApp;
|
||||
|
Loading…
x
Reference in New Issue
Block a user