Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt Qbs自定义模块不工作_Qt_Qbs - Fatal编程技术网

Qt Qbs自定义模块不工作

Qt Qbs自定义模块不工作,qt,qbs,Qt,Qbs,我想制作一个模块,使用QtRO repc编译器从.rep文件生成.h文件 我对模块进行了编码,但当我尝试将其加载到应用程序产品中时,它不会加载并禁用该产品 模块位于C:\Users\User\qt\qbs中 Qbs模块副本。Qbs: import qbs Module { property bool source: true FileTagger { patterns: "*.rep" fileTags: ["rep"] } Ru

我想制作一个模块,使用QtRO repc编译器从.rep文件生成.h文件

我对模块进行了编码,但当我尝试将其加载到应用程序产品中时,它不会加载并禁用该产品

模块位于C:\Users\User\qt\qbs中

Qbs模块副本。Qbs:

import qbs

Module {
    property bool source: true
    FileTagger {
        patterns: "*.rep"
        fileTags: ["rep"]
    }
    Rule {
       inputs: ["rep"]
       Artifact {
           fileTags: ["txt_output"]
       }
       prepare: {
           var cmd = new Command();
           cmd.program = "repc.exe";
           if source {
               cmd.arguments = ["-i", "rep", "-o", "source", input.filePath];
           } else {
               cmd.arguments = ["-i", "rep", "-o", "replica", input.filePath];
           }
           console.log("repc on : ", input.filePath);
           return [cmd];
       }
    }
}
product.qbs:

import qbs

Application {
    name: "ServiceExposer"
    Depends { name: "cpp" }
    Depends { name: "Qt.core" }
    Depends { name: "Qt.remoteobjects" }
    Depends { name: "replica" }
    files: [
        "main.cpp",
        "service_exposer.rep"
    ]
}
project.qbs:

import qbs

Project {
    references: ["ServiceExposer/ServiceExposer.qbs"]
    qbsSearchPaths: "C:\Users\User\qt\qbs"
}
我不知道我在哪里犯了错误


提前感谢您的帮助。

在进一步挖掘文档和源代码后,我成功地使其工作,我将与您分享工作模块

导入此模块时,如果项目中存在任何.rep文件(QtRO(远程对象))模块远程对象定义),它将调用repc编译器并编译它们,并将生成的.h文件放入源目录中

仍然没有完成,我没有找到一种方法来操作产品项的files属性以自动向其中添加.h

import qbs
import qbs.FileInfo

Module {
    FileTagger {
        patterns: ["*.rep"]
        fileTags: ["repc-rep"]
    }
    Rule {
        inputs: ["repc-rep"]
        Artifact {
            filePath: repc_" + FileInfo.baseName(input.fileName) + "_source.h"
            fileTags: ["cpp"]
        }
        prepare: {
            var cmd = new Command();
            cmd.description = "repc " + input.fileName;
            cmd.program = "repc.exe"
            cmd.arguments = ["-i", "rep", "-o", "source", input.filePath, output.filePath];
            var cmd2 = new JavaScriptCommand();
            cmd2.silent = true;
            cmd2.sourceCode = function() {
                 File.copy(output.filePath, FileInfo.path(input.filePath) + "/" + output.fileName);
            }
            return [cmd, cmd2];
        }
    }
}
要使此模块正常工作,repc.exe必须位于您的路径中

欢迎任何建议

  • 如果它是头文件,为什么要给它“cpp”标签?不应该是“水电站”吗
  • 您将文件放入源目录的原因是什么?您是否计划将其添加到存储库中?通常,构建工件(不管它们是二进制文件还是人类可读文件)应该位于构建目录内,以免“污染”源树
  • 您没有提到模块现在以何种方式不适合您,因此很难诊断问题。您应该提及您预期会发生什么,以及发生了什么(给出具体的错误消息,如果有)

  • @Chritian Kandeler-我不知道存在hpp标记,我将其放在源目录中,以便从其他类引用它。工作版本在我对这篇文章的回答中。当它不起作用时,只需禁用项目,不要告诉我模块中出现了什么问题。@Chritian Kandeler-我不想把这篇文章放到一篇新文章中,什么是多路传输规则?这是什么意思?当QB告诉您规则中存在冲突且规则不是多路复用时,这意味着什么?我确实修复了它,这是因为moc发现扩展名为.h的文件是相同的(一个是由repc在构建目录中生成的,另一个是我在源目录中复制的),我不得不修改我的模块以删除build目录中的模块。