Qt

Qt在Xcode原生Mac Cocoa应用中使用时的Could not find the Qt platform plugin问题

最近在测试Xcode原生Mac Cocoa GUI应用中直接调用Qt GUI时遇到了一个报错找不到native plugin的问题。先记录下操作系统是:macOS 13.4,Xcode版本是:Version 14.3 (14E222b),Qt版本是:6.8.0。用法是在Xcode中新建一个App,interface选的xib(但应该没关系,因为根本没用任何xcode GUI编辑功能),然后在生成的的代码项目中手动加入各种依赖的Qt Framework,并设置好include,lib,rpath等各种路径。代码也是从网上搜到的很简单的创建Qt空间后,通过winId的方式(这是Qt6新改的,以前的Qt5及旧版本需要使用QMacNativeWidget)挂到NSView下,如下:

1
2
3
4
5
6
7
8
9
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    QPushButton* btn = new QPushButton("testtttttttttttt");
    NSView* viewBtn = (__bridge NSView*)((void*)btn->winId());
    [self.window.contentView addSubview:viewBtn];
    btn->show();
    [viewBtn setNeedsDisplay:YES];
    [self.window makeKeyAndOrderFront:self.window];
}

需要注意的是开了ARC后的winId返回到NSView*的cast,c cast,c++ cast直接用都不行,查了半天才找到这种__bridge cast配合强转void*的可行方式。

然后运行,发现了标题中的报错信息:

Continue reading…

[ZT]Qt开发环境安装程序跳过账号登录的方法

记录一下,Qt开源版开发环境安装程序,跳过账号登录的方法,参考自:

https://www.openguru.com/2021/03/install-qt-creator-without-qt-account.html

首先是要下载Qt离线安装程序,在这里:https://www.qt.io/offline-installers,然后安装时会发现还是需要登入账号,此时linux系系统可以设置无效proxy,如上面参考链接中提到的方法,而windows则可以通过禁用网络连接的方式跳过

Xcode升级后导致原Qt项目构建失败的问题

原有使用Qt Creator 4.0.2创建的跨平台GUI项目,在近日Xcode升级至8.0后,出现了构建失败的问题,错误信息如下:

clang: warning: no such sysroot directory: ‘/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk’
In file included from ../FbxVertexMerger/main.cpp:1:
In file included from ../FbxVertexMerger/mainwindow.h:4:
In file included from ../../../../Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from ../../../../Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtWidgets.framework/Headers/qwidget.h:43:
In file included from /Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtGui.framework/Headers/qwindowdefs.h:43:
In file included from /Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qglobal.h:81:
/Users/wzkres/Qt5.7.0/5.7/clang_64/lib/QtCore.framework/Headers/qsystemdetection.h:95:12: fatal error: ‘TargetConditionals.h’ file not found
# include <TargetConditionals.h>

显然,问题出在MacOSX10.11.sdk这个位置,升级后的MacOSX SDK变为了MacOSX10.12.sdk,那么如何让Qt使用新版本的SDK呢?很简单,修改Qt项目的.pro文件,加入 Continue reading…