编译日志如下: 00:46:54: 为项目 untitled1 执行步骤 ... 00:46:54: 正在启动 "G:\QtCommunity\Tools\CMake_64\bin\cmake.exe" --build G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug --target all
[0/2 0.0/sec] Re-checking globbed directories... [1/9 0.4/sec] Automatic MOC and UIC for target untitled1 [2/9 0.7/sec] Running AUTOMOC file extraction for target untitled1 [3/9 0.9/sec] Running moc --collect-json for target untitled1 [4/9 0.6/sec] Building CXX object CMakeFiles/untitled1.dir/untitled1_autogen/mocs_compilation.cpp.o [5/9 0.8/sec] Building CXX object CMakeFiles/untitled1.dir/main.cpp.o [6/9 0.9/sec] Building CXX object CMakeFiles/untitled1.dir/mainwindow.cpp.o [7/9 0.9/sec] Linking CXX shared module libuntitled1_arm64-v8a.so [8/9 1.0/sec] Copying untitled1 binary to apk folder 00:47:03: The command "G:\QtCommunity\Tools\CMake_64\bin\cmake.exe --build G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug --target all" finished successfully. 00:47:03: 正在启动 "G:\QtCommunity\6.9.1\mingw_64\bin\androiddeployqt.exe" --input G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-untitled1-deployment-settings.json --output G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-build-untitled1 --android-platform android-35 --jdk G:/jdk17 --gradle
Generating Android Package Input file: G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-untitled1-deployment-settings.json Output directory: G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-build-untitled1/ Application binary: untitled1 Android build platform: android-35 Install to device: No Skipping createRCC Starting a Gradle Daemon, 1 incompatible and 9 stopped Daemons could not be reused, use --status for details
Task :preBuild UP-TO-DATE Task :preDebugBuild UP-TO-DATE Task :mergeDebugNativeDebugMetadata NO-SOURCE Task :javaPreCompileDebug Task :generateDebugResValues Task :checkDebugAarMetadata Task :mapDebugSourceSetPaths Task :generateDebugResources Task :mergeDebugResources Task :packageDebugResources Task :createDebugCompatibleScreenManifests Task :extractDeepLinksDebug Task :parseDebugLocalResources
Task :processDebugMainManifest package="org.qtproject.example.untitled1" found in source AndroidManifest.xml: G:\Qtfile\QtProgram\untitled1\build\Qt_6_9_1_Clang_arm64_v8a-Debug\android-build-untitled1\AndroidManifest.xml. Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported, and the value is ignored. Recommendation: remove package="org.qtproject.example.untitled1" from the source AndroidManifest.xml: G:\Qtfile\QtProgram\untitled1\build\Qt_6_9_1_Clang_arm64_v8a-Debug\android-build-untitled1\AndroidManifest.xml.
Task :processDebugManifest Task :mergeDebugShaders Task :compileDebugShaders NO-SOURCE Task :generateDebugAssets UP-TO-DATE Task :mergeDebugAssets Task :compressDebugAssets Task :processDebugJavaRes NO-SOURCE Task :checkDebugDuplicateClasses Task :mergeDebugJniLibFolders Task :mergeLibDexDebug Task :validateSigningDebug Task :writeDebugAppMetadata Task :writeDebugSigningConfigVersions Task :processDebugManifestForPackage Task :mergeDebugNativeLibs Task :mergeDebugJavaResource Task :processDebugResources Task :compileDebugJavaWithJavac Task :dexBuilderDebug Task :desugarDebugFileDependencies Task :mergeProjectDexDebug Task :stripDebugDebugSymbols Task :mergeExtDexDebug Task :packageDebug Task :createDebugApkListingFileRedirect Task :assembleDebug
[Incubating] Problems report is available at: file:///G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-build-untitled1/build/reports/problems/problems-report.html
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.12/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 23s 33 actionable tasks: 33 executed Android package built successfully in 28.935 ms. -- File: G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-build-untitled1//build/outputs/apk/debug/android-build-untitled1-debug.apk 00:47:32: The command "G:\QtCommunity\6.9.1\mingw_64\bin\androiddeployqt.exe --input G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-untitled1-deployment-settings.json --output G:/Qtfile/QtProgram/untitled1/build/Qt_6_9_1_Clang_arm64_v8a-Debug/android-build-untitled1 --android-platform android-35 --jdk G:/jdk17 --gradle --gdbserver" finished successfully. 00:47:32: Elapsed time: 00:38.
mainwindow.h 如下: #ifndef MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QLabel>
class MainWindow : public QMainWindow { Q_OBJECT
public: MainWindow(QWidget *parent = nullptr); ~MainWindow();
protected: void mousePressEvent(QMouseEvent *event) override;
private: QLabel *label; };
#endif // MAINWINDOW_H
mainwindow.cpp 如下: #include "mainwindow.h" #include <QMouseEvent> #include <QFont> #include <QDebug>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // 设置窗口大小 resize(400, 300);
// 创建 label 但先不显示文字 label = new QLabel(this); label->setText(""); label->setAlignment(Qt::AlignCenter); label->setGeometry(rect()); // 占满整个窗口 label->setFont(QFont("Arial", 24));
}
MainWindow::~MainWindow() { }
void MainWindow::mousePressEvent(QMouseEvent *event) { Q_UNUSED(event); label->setText("Hello World"); qDebug() << "屏幕被点击,显示 Hello World"; }
]]>我做了个音乐播放器,引用的外部库只有 libmpv ,还引用了 qt 的 sql ,用于处理 sqlite 数据库。问题可能主要出现在这两个。 编译调试运行都没啥问题,开发完成想要打包发布,macdeployqt6 打包出来的却无法运行。 仔细分析认为有些依赖有问题,比如编译的时候 ok ,理论上所有依赖在本机都已经齐全,macdeployqt6 打包却告知会引用 Postgres.app 下面的一个库,而这个 app 我之前根本没有安装。类似的还有 libjxl_cms.0.11.dylib libjxl.0.11.dylib 等图片相关的库,需要额外下载才能打包,编译运行却不需要。
换思路采用 xcode 来打包,先 qmake make 生成 xcode 项目,导入后可以编译运行,archive 打包逐个测试依赖的库,发现不集成部分依赖的 Framework 可运行,全部集成却不行。
第二个问题是,解决完上述依赖文件后,打包的程序.app 还是无法直接双击打开,看汇报日志出现 signed 、ns 等模糊问题。更奇葩的是,有时候采用 lldb 对打包的程序进行调试可以运行,直接打开 app 却打不开。 Termination Reason: Namespace SIGNAL lldb 报错 :qianqianplayer[73941:807292] This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem
求有经验的人指点迷津,如果您不知道我在说啥,可能您难以解决我的问题,就随便看看。
如有任何思路,不胜感激,困扰好几天了。
]]>不知道这个 1127, FromFilemap ,是从哪里输出的
]]>代码如下,还想请教一点,为什么单击的时候也会出现菜单呢?
void MainWindow::SltTrayClicked(QSystemTrayIcon::ActivationReason reason) { switch (reason) { case QSystemTrayIcon::Trigger: // 单击 if (!this->isVisible()) { this->show(); } break; case QSystemTrayIcon::Context: // 右击 if (!m_trayMenu->isVisible()) { m_trayMenu->show(); } break; default: break; } }
]]>TimerThread
: TimerThread* t_thread = new TimerThread(); QThread* thread = new QThread(); t_thread->moveToThread(thread);
我想通过界面上的一个按钮ui->startThread
来启动子线程:
connect(ui->startThread, &QPushButton::clicked, thread, &QThread::start);
但是程序报错:error: static assertion failed: Signal and slot arguments are not compatible.
但是我使用了另一种方法连接信号与槽,程序又能正常运行:
connect(ui->startThread, &QPushButton::clicked, thread, [&](){ thread->start(); });
报错的意思是发送的信号参数与槽函数的参数没有对应。但是当我自己定义一个槽函数void testFun(int);
,并且,点击按钮时发出的信号所携带的参数同样与我自定义的槽函数的参数不能对应,但是程序却能正确运行。
connect(ui->startThread, &QPushButton::clicked, this, &MainWindow::testFun);
我非常困惑,大佬能否为我指点迷津,非常感谢🙏🙏🙏
]]>form_B
和form_C
在form_A
下创建,然后form_D
在form_C
下创建。form_B
如何从form_D
获得信号? 我的想法是先将信号从form_D
传递到form_C
,然后再传递到form_A
,最后form_A
将信号传递到form_B
。然而,这样会有很多与各种信号相关的连接,并且很难管理。 真诚地请教下是否有其他方法可以管理这么多信号。真诚地询问是否有更方便的方法来管理信号,将信号从form_D
传输到form_B
。
class MyThread : public QObject{ Q_OBJECT void work(){ qDebug()<<"MyThread::work() thread id: "<<QThread::currentThreadId()<<"\n"; } } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { qDebug()<<"main thread id: "<<QThread::currentThreadId()<<"\n"; QThread* subThread = new QThread; MyThread* my_thread = new MyThread; my_thread->moveToThread(thread1); my_thread->start(); qDebug()<<"00000000"; my_thread->work(); connect(ui->pushButton, &QPushButton::clicked, my_thread, &MyThread::work); connect(ui->pushButton, &QPushButton::clicked, this, [=]{ qDebug()<<"11111111"; my_thread->work(); }); connect(ui->pushButton, &QPushButton::clicked, my_thread, [=]{ qDebug()<<"22222222"; my_thread->work(); }); }
程序执行结果:
main thread id: 0x1a70 00000000 MyThread::work1() thread id: 0x1a70 11111111 MyThread::work1() thread id: 0x1a70 MyThread::work1() thread id: 0x698 22222222 MyThread::work1() thread id: 0x698
请问为何在主窗口中直接调用 my_thread 和
connect(ui->pushButton, &QPushButton::clicked, this, [=]{ my_thread->work(); });都是在主线程中执行,而其他两种调用方式就能正确在子线程中执行?
#ifndef PLAYDIALOG_H #define PLAYDIALOG_H #include <memory> #include <QVBoxLayout> #include <QDialog> class QPushButton; class PlayDialog : public QDialog { Q_OBJECT public: explicit PlayDialog(QWidget* parent = nullptr); private: QVBoxLayout* m_layout; QPushButton* m_button1; std::shared_ptr<QPushButton> m_button2; QSharedPointer<QPushButton> m_button3; }; #endif // PLAYDIALOG_H
#include "playdialog.h" #include <memory> #include <QDialog> #include <QLayout> #include <QPushButton> #include <QVBoxLayout> PlayDialog::PlayDialog(QWidget* parent) : QDialog(parent), m_layout(new QVBoxLayout(this)) { m_button1 = new QPushButton("BUTTON1", this); m_button2 = std::make_shared<QPushButton>("BUTTON2", this); m_button3 = QSharedPointer<QPushButton>::create("BUTTON3", this); m_layout->addWidget(m_button1); m_layout->addWidget(m_button2.get()); m_layout->addWidget(m_button3.get()); setLayout(m_layout); }
其中的 QPushButton 都设置了 QDialog 窗体为父控件,m_button2
和m_button3
分别用 C++原生和 Qt 的智能指针进行了包装。如果这个时候关掉父窗体,因为父子级关系三个按钮都会被释放,但是受智能指针管理的m_button2
和m_button3
按理说也会被释放,这种时候会存在二次删除风险吗?是不是在 Qt 中不应该用智能指针管理设置了父子级关系的 QWidget 控件?还是说 Qt 封装过的 QSharedPointer 可以放心使用?
本身 IDE 的话 Visual Studio 因为写过 C#熟悉一点,然后 JetBrains 家的 IDE 完全没有实际使用过。
想知道现在写 Qt 的主流 IDE 工具是什么?是用那个官方的 Qt Creator 还是用其他 IDE 工具开发体验好一点?
]]>目前按照 qt creator 向导能够编译和加载简单的示例插件,但是尝试使用 Debugger 类的时候会出现编译错误,提示无法解析的外部符号。我尝试在 pro 文件中添加了对 debugger 的依赖,似乎没有什么效果。
我想问问有没有人做过类似的事,能否提供一些指点?关于插件开发我只找到 VCreateLogic 公司的一个文档,关于 creator 插件开发的官方文档没怎么找到?
]]>但是所有第三方软件读到都是 82OA12W5KMH5
请教有没有可以直接获取正确序列号的命令行,或可以带参数直接输出硬盘序列号的第三方工具?
]]>仔细看报错内容,发现是 make 的过程中,windres 报错,最后在 stackoverflow 上找到临时解决方法: windres error
在生成的 makefile 中给 windres 添加--use-temp-file 选项
但是在临时生成的 makefile 中直接改毕竟不是长久之计,于是继续搜索,发现: qmake.conf
修改相应 qmake.conf 中的 QMAKE_RC 即可
比如在 win32-g++/qmake.conf 中添加一行:
QMAKE_RC += --use-temp-file
至此,问题解决(没有尝试其他版本的 Qt ,不知道是不是版本相关问题)
]]>它这个文件 files/qmake.mk 用的是 qmake ,但是 qt6 本身使用的编译方法和 qt5 时候不一样了。有大佬会这个吗?(orz~~
]]>不知道能不能闭源商用。
]]>附上我的 pyqt 代码片段:
process = QProcess() process.setWorkingDirectory(f"{workDir}") command = f"mpiexec -n {mpiNum} {SG_INTEXE}" process.start(command) while True: if self.stopOneFlag: process.kill() process.waitForFinished(-1) process = None self.logChange.emit(f"{name}stop !\n") logging.info(f"{name}stop !") break
]]>熟悉 Qt 的大佬指点一下,如何改善 QtWidget 的 Wayland 兼容性。
创建一个 QUdpSocket ,bind 一个本地的 IP 如 192.168.1.200 ,结果用 writeDatagram 无法发送数据。
大家遇到过这个问题吗?
]]>buffer[i % BufferSize] = "ACGT"[QRandomGenerator::global()->bounded(4)]; // 写入数据 fprintf(stderr, "%c", buffer[i % BufferSize]); // 读取数据
这个难道是线程安全的吗?
qt 自带代码如下:
#include <QtCore> #include <stdio.h> #include <stdlib.h> const int DataSize = 100000; const int BufferSize = 8192; char buffer[BufferSize]; QWaitCondition bufferNotEmpty; QWaitCondition bufferNotFull; QMutex mutex; int numUsedBytes = 0; class Producer : public QThread { public: Producer(QObject *parent = NULL) : QThread(parent) { } void run() override { for (int i = 0; i < DataSize; ++i) { mutex.lock(); if (numUsedBytes == BufferSize) bufferNotFull.wait(&mutex); mutex.unlock(); buffer[i % BufferSize] = "ACGT"[QRandomGenerator::global()->bounded(4)]; mutex.lock(); ++numUsedBytes; bufferNotEmpty.wakeAll(); mutex.unlock(); } } }; class Consumer : public QThread { Q_OBJECT public: Consumer(QObject *parent = NULL) : QThread(parent) { } void run() override { for (int i = 0; i < DataSize; ++i) { mutex.lock(); if (numUsedBytes == 0) bufferNotEmpty.wait(&mutex); mutex.unlock(); fprintf(stderr, "%c", buffer[i % BufferSize]); mutex.lock(); --numUsedBytes; bufferNotFull.wakeAll(); mutex.unlock(); } fprintf(stderr, "\n"); } signals: void stringConsumed(const QString &text); }; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); Producer producer; Consumer consumer; producer.start(); consumer.start(); producer.wait(); consumer.wait(); return 0; }
]]>