使用Qt编译项目后,将文件复制到构建目录

时间:2011-10-17 14:41:05

标签: qmake

我有一个文件“settings.ini”,它需要驻留在Qt可执行文件旁边。

我可以在Qt Creator中添加一个自定义构建步骤,调用类似这样的内容:

copy %{sourceDir}/settings.ini %{buildDir}/settings.ini

到目前为止这种方法很有用,但我想将它包含在* .pro文件中,这样我就可以把它放在我们的SVN中。

我怎样才能使用qmake / .pro-files?

4 个答案:

答案 0 :(得分:12)

您可能想在QMake中使用INSTALLS keyword。它需要您在构建后运行make install,但它确实可以跨平台运行。

install_it.path = %{buildDir}
install_it.files += %{sourceDir}/settings.ini

INSTALLS += install_it

答案 1 :(得分:11)

要将%{sourceDir}/settings.ini复制到构建目录,不要要求调用make install,请使用:

copydata.commands = $(COPY_DIR) $$PWD/settings.ini $$OUT_PWD
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata

$$PWD是当前.pro文件的路径。如果您的settings.ini文件与项目文件不在同一目录中,请使用$$PWD/more_dirs_here/settings.ini

之类的内容

注意:我找到了这个解决方案here。我建议阅读整篇文章,因为它解释了它的工作原理。

答案 2 :(得分:2)

对于osx bundle,你可以这样处理它 见Resource files in OS X bundle

将此项添加到项目文件中:

APP_QML_FILES.files = path/to/file1.qml path/to/file2.qml
APP_QML_FILES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_QML_FILES

此示例将文件复制到Contents / Resources

答案 3 :(得分:0)

与Windows和Mac OSX开发环境兼容:

将{AppName}更改为相应的应用程序名称

 List<Request> requests = new List<Request> { };

        DocumentsResource.GetRequest req = dservice.Documents.Get(docid);
        Document doc = req.Execute();


        int max = 0;
        for (int i = 0; i < doc.Body.Content.Count; i++)
        {
            if (doc.Body.Content[i].EndIndex.Value > max)
            {
                max = doc.Body.Content[i].EndIndex.Value;
            }
        }

        if (max < 3)
        {
         //   requests.Add(new Request() { DeleteNamedRange = new DeleteNamedRangeRequest() { Name = "BoddyTitle" } });
         //   requests.Add(new Request() { DeleteNamedRange = new DeleteNamedRangeRequest() { Name = "BoddyContent", } });
            requests.Add(new Request() { InsertText = new InsertTextRequest() { Text = "\n\nx", Location = new Location { Index = 1 } } });
            requests.Add(new Request() { InsertText = new InsertTextRequest() { Text = "\n\nx", Location = new Location() { SegmentId = "", Index = 4 } } });
            requests.Add(new Request() { CreateNamedRange = new CreateNamedRangeRequest() { Name = "BoddyTitle", Range = new Range() { SegmentId = "", StartIndex = 3, EndIndex = 4 } } });
            requests.Add(new Request() { CreateNamedRange = new CreateNamedRangeRequest() { Name = "BoddyContent", Range = new Range() { SegmentId = "", StartIndex = 6, EndIndex = 7 } } });
        }

                  
        //                   requests.Add(new Request() { DeleteContentRange = new DeleteContentRangeRequest() { Range = new Range { StartIndex = 1, EndIndex = max - 1 } } });


        if (textBox1.Text != "" && textBox2.Text != "")
        {
          requests.Add(new Request() { ReplaceNamedRangeContent = new ReplaceNamedRangeContentRequest() { Text = textBox1.Text.Replace("\r\n", "\n"), NamedRangeName = "BoddyTitle" } });
          requests.Add(new Request() { ReplaceNamedRangeContent = new ReplaceNamedRangeContentRequest() { Text = textBox2.Text.Replace("\r\n", "\n"), NamedRangeName = "BoddyContent" } });
           
        }
          else { MessageBox.Show("Textbox Empty" ); }

        if (requests.Count >0)
        {
            BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest { Requests = requests };
            dservice.Documents.BatchUpdate(body, docid).Execute();Process.Start("https://docs.google.com/document/d/doc_id/edit?usp=sharing");
        }

如果有人在评论中发布Unix解决方案,很高兴添加Unix支持。