使用QT在Mac下建立L2TP VPN拨号连接

近日研究使用QT在Mac下进行L2TP VPN拨号连接,这就涉及到了QT与Objective-C的混合编程。花了2天时间看看Objective-C的语法(简直是逆天了),再花5天时间才写出来这个测试工程,它的功能包括:如何建立VPN连接服务、删除VPN连接服务、启动连接、断开连接、判断连接状态。下面分享一下Qt如何与Objective-C混合编程。
Pro文件里加入需要引用的Framework
注意:1、类的头文件.h里面不能包含任何Objective-C的东西;
           2、类的实现如果是混编的,后缀名应该修改为.mm;
           3、混编的.mm加入 到工程时使用OBJECTIVE_SOURCES;
            4、工程中需要链接的Framework路径要正确。
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += main.cpp
HEADERS += l2tp_mac.h
macx {
OBJECTIVE_SOURCES += l2tp_mac.mm
QMAKE_LFLAGS += -F /System/Library/Frameworks/
LIBS += -framework SystemConfiguration
LIBS += -framework CoreFoundation
LIBS += -framework Foundation
LIBS += -framework NetworkExtension
LIBS += -framework Security
LIBS += -framework AppKit
}
源码路径: https://github.com/qiyugfh/L2tpDialMac
如果这个测试工程帮助到了你,记得打Call哦!

猜你喜欢

转载自blog.csdn.net/m0_37406679/article/details/79308671
今日推荐