今天怀着无比激动的心情写下这篇文章,因为QT在rax中使用成功
QT中的ARX配置
LoadQtDlls.pro
TARGET = QTARXLoadQtDlls
#the sdk include path
INCLUDEPATH += "D:\ObjectARX 2022\inc"
INCLUDEPATH += "D:\ObjectARX 2022\inc-x64"
#rxapi.lib; acdb21.lib; acge21.lib; acad.lib; ac1st21.lib; accore.lib;
LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lrxapi
LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lacdb24
LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lacge24
LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lacad
LIBS+= -L"D:\ObjectARX 2022\lib-x64" -lac1st24
LIBS+= -L"D:\ObjectARX 2022\lib-x64" -laccore
#DEF_FILE
DEF_FILE += $$PWD/AcRxDefault.def
#use md dll
QMAKE_CXXFLAGS += /MD
#change .dll to .arx
TARGET_EXT = .arx
#remove _DEBUG
DEFINES -= _DEBUG
DEFINES += _OBJECT_ARX_VERSION_X64_=2022
QT += core
QT += gui
QT += widgets
QT += qml
#Qt project template
TEMPLATE = lib
SOURCES += this_main.cpp \
form.cpp
RESOURCES += \
images.qrc
DESTDIR = $$PWD/../../release/Autocad2022
FORMS += \
form.ui
HEADERS += \
form.h
ARX入口书写
this_main.cpp
#pragma warning( push)
#pragma warning (disable: 4189 4100 )
#include <Windows.h>
#include <arxHeaders.h>
#pragma warning( pop)
#include <string_view>
using namespace std::string_literals;
#include <QtWidgets>
#include <QtQml>
#include<QMessageBox>
inline void HellowWorld() {
acutPrintf(LR"(Hellow Word!
)");
}
inline void HellowWorldARX() {
// QJSEngine varE;
// varE.evaluate( QString("1+1") );
{
QMessageBox varBox ;
varBox.setText(("Hellow World!"));
varBox.exec() ;
}
auto varDataTime = QDateTime::currentDateTime().toString().toStdWString();
varDataTime = LR"(Hellow World!)" + varDataTime ;
acutPrintf(varDataTime.c_str());
}
namespace {
namespace _cpp_private {
const std::string qtApplicationPath ="123";/*!!!*/
//#if _OBJECT_ARX_VERSION_X64_ == 2018
// u8R"(D:\Program Files\AutoCAD 2018\acad.exe)"s;
//#else
// u8R"(D:\Program Files\AutoCAD 2022\AutoCAD 2022\acad.exe)";
//#endif
inline int & getArgc() {
static int ans;
ans = 1;
return ans;
}
inline char** getArgv() {
static char acadpath[] =u8R"(D:\Program Files\AutoCAD 2022\AutoCAD 2022\acad.exe)";
static char *argv[] = { nullptr };
std::copy(qtApplicationPath.begin(), qtApplicationPath.end(),
static_cast<char*>(acadpath));
argv[0] = static_cast<char *>(acadpath);
return argv;
}
}
}/*namespace*/
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) {
switch (msg) {
case AcRx::kInitAppMsg: {
acrxDynamicLinker->unlockApplication(pkt);
acrxRegisterAppMDIAware(pkt);
/*****************************************/
{
if (qApp == nullptr) {
/*create the qt applicaton and never destory it*/
auto varQtApplication =
new QApplication(_cpp_private::getArgc(), _cpp_private::getArgv());
(void)varQtApplication;
}
{
/*force to load images plugins*/
QImage varImage{ QString(":/png/this.png") };
varImage.width();
varImage.height();
}
}
/*****************************************/
acedRegCmds->addCommand(
L"SSTD_GLOBAL_CMD_GROUP",
L"HellowWorld",
L"HellowWorld",
ACRX_CMD_MODAL,
&HellowWorldARX);
}break;
case AcRx::kUnloadAppMsg: {}break;
default:break;
}
return AcRx::kRetOK;
}
/********************************/
代码结构
![](https://i-blog.csdnimg.cn/blog_migrate/2970b331261b3759112abe067d8b88ab.png)
结果展示
![](https://i-blog.csdnimg.cn/blog_migrate/26cf0ad62377a7be1e7ecd368ab00d5b.png)
![](https://i-blog.csdnimg.cn/blog_migrate/24189642b6b28b03f02b20c6c6e12a00.png)
this.png
![](https://i-blog.csdnimg.cn/blog_migrate/0e2e16d1b8534d8c555c25abe9f3a4e6.png)
生成的arx
![](https://i-blog.csdnimg.cn/blog_migrate/fa4baaf890620b318b9e0f703528cb73.png)
细节注意
arx同级目录的dll
arx同级目录的dll是qt编译出的,不然无法加载
![](https://i-blog.csdnimg.cn/blog_migrate/c34583ce21464b770236eb6513cee02b.png)
使用的命令D:\Qt\5.15.2\msvc2019_64>windeployqt.exe C:\Users\yhx\Downloads\ObjectArxAutocad2018Vs2017Qt59-master\ObjectArxAutocad2018Vs2017Qt59-master\release\Autocad2022\QTARXLoadQtDlls.arx
CAD加载arx
使用命令arx
![](https://i-blog.csdnimg.cn/blog_migrate/7f311d4009bf38bd206d6011f8a02c2b.png)
![](https://i-blog.csdnimg.cn/blog_migrate/ed1c426a5ebb01d66689aaa0a42ff5c4.png)
QT项目配置
![](https://i-blog.csdnimg.cn/blog_migrate/157ccc03328973b2399c1f2ecdd51ca1.png)
参考https://github.com/nanguazhude/ObjectArxAutocad2018Vs2017Qt59/blob/master/objectarx.pro
git的项目地址,持续更新中
QTObjectARX2022/LoadQtApplication at main · Mysunshinecode/QTObjectARX2022 (github.com)