V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
minecraftyusei
V2EX  ›  Qt

qt 新手求助: No documents matching 'ui_mainwindow.h' could be found

  •  
  •   minecraftyusei · 4 天前 · 365 次点击

    新手上路,整了一个非常单纯的小工程(拿 ai 写的),然后在 ui 设计时右键 Pushbutton 转到槽时被这个问题干碎了,一头雾水,甚至不知道怎么排除错误。

    编译日志如下: 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"; }

    9 条回复    2025-07-03 14:52:21 +08:00
    minecraftyusei
        1
    minecraftyusei  
    OP
       4 天前
    吐槽一个:在学 qt 之前我反而得先学会怎么用 qtcreater ,更头疼了。。。
    想起 visual studio 也是如此,sad
    OBJECTION
        2
    OBJECTION  
       4 天前
    丢给 cursor 应该也可以的吧? 我最近也用 qt 写了几个工具 有一种是直接使用 visual studio 的插件编译 不依赖 pro 文件。 还有一种是直接使用 qt creator 也就说使用 pro 文件的 .
    minecraftyusei
        3
    minecraftyusei  
    OP
       4 天前
    @OBJECTION 倒不是说丢给谁,我想知道怎么去找我犯错在哪了。毕竟我没学过 qt ,ai 说的话我就没办法辨别里面是不是掺了假,比如有时候它叫我去找某某选项卡下面的某某选项,一看根本没有这个选项卡。然后在用 qt 编程之前,我又得先学会怎么用 qtcreator 这个软件。被这么个报错缠着,就很丧气
    calvinHxx
        4
    calvinHxx  
       3 天前
    ??? 为啥 qwidget 的东西用的是 android 的编译器?
    OBJECTION
        5
    OBJECTION  
       3 天前
    @minecraftyusei 这个。。 你可能得按照我上面说的两种再 windows 构建的方式去搜一下视频。。 不然很容易呗 ai 带歪。。

    然后 4 楼问的 你是再弄交叉编译的??
    minecraftyusei
        6
    minecraftyusei  
    OP
       3 天前
    @calvinHxx 就。。我发现 qt 能写安卓的 app 后就兴致勃勃的想学着自己写着玩,自己琢磨着把该配置的配置完后给 ai 提了个要求要他帮我出一个点击屏幕就能显示 helloworld 的代码。然后我在这个的基础上想给他加一个 pushbutton ,但是怎么都添加不了它的槽函数。
    minecraftyusei
        7
    minecraftyusei  
    OP
       3 天前
    @OBJECTION 就。。我发现 qt 能写安卓的 app 后就兴致勃勃的想学着自己写着玩,自己琢磨着把该配置的配置完后给 ai 提了个要求要他帮我出一个点击屏幕就能显示 helloworld 的代码。然后我在这个的基础上想给他加一个 pushbutton ,但是怎么都添加不了它的槽函数。
    calvinHxx
        8
    calvinHxx  
       3 天前
    qt 是可以写安卓的东西 不过需要安装配置好安卓相关的 NDK 、JDK, 然后 UI 框架需要使用 QML, QWidget 一般是用在 PC 的老 UI 框架,编译报错是肯定的。
    最新的 Qt6 版本的![QML Book]( https://www.qt.io/product/qt6/qml-book)已经被官方收录了简单了解下, 明确基本概念后,再用 AI 去生成代码或许是更科学的打开方式?
    minecraftyusei
        9
    minecraftyusei  
    OP
       3 天前
    @calvinHxx 是。。这么个道理,我自觉自己新手乱上路这也不懂那也不懂,很想有本非常大的说明书能把 qt 软件如何使用、qt 的程序如何写都一起包括进去

    但是话说回来,这个编译报错就一定没法解决的吗,qwidget 就没办法在安卓平台上使用吗?
    我后来跟 ai 缠斗了许久,它大概就是车轱辘跟我说你的头文件啊 cmake 啊有诸多问题。老实说我的代码水平还停留在大学本科一般通识课的 using namespace std 那里,他说的东西甚至我没办法知道他对不对。。。

    另外问一句,程序员们都是无压力看懂各种英文说明文档的吗,我看了层主发的那个 qmlbook ,一进去一堆英文我的大脑就开始排异反应了 ( X﹏X )
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5915 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:52 · PVG 09:52 · LAX 18:52 · JFK 21:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.