Automating Qt Help Compilation from Project Files

Posted in Coding | Projects 0

It always bugs me that while the UI and moc generation is automatic and doesn’t require much effort to make happen in Qt Creator, the help file generation has no such automation that I can find built-in to the IDE.  Here’s what I add to my project file to compile the different help files and put them where they need to be for the built program to access.

Example docs.pri


# Documentation

OTHER_FILES += \
    docs/docs.html \
    docs/docs1.png \
    docs/docs2.png \
    docs/docs.qhp \
    docs/docs.qhcp

HEADERS += \
    docs/helpwindow.h \
    docs/helpbrowser.h

SOURCES += \
    docs/helpwindow.cpp \
    docs/helpbrowser.cpp

FORMS += \
    docs/helpwindow.ui

defineTest(helpCopyCommands) {
    files = $$1
    for(FILE, files) {

              # get rid of trailing 'docs/'

        FILE ~= s,docs/,,

        FILE = $$PWD/$$FILE

              # Replace slashes in paths with backslashes for Windows
        win32:FILE ~= s,/,\\,g

        MYFILECOPY += @echo "Copying $$FILE" $$escape_expand(\\n\\t)
        MYFILECOPY += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t)
    }
    export(MYFILECOPY)
}

help_copy.target = dox
help_copy.commands = @echo "Building Help Files in $$DDIR"  $$escape_expand(\\n\\t)
QMAKE_EXTRA_TARGETS += help_copy
POST_TARGETDEPS += dox

win32 {

  CONFIG += help
  CONFIG(debug, debug|release) {
        DDIR = $$OUT_PWD/debug/docs
  }
  CONFIG(release, debug|release) {
        DDIR = $$OUT_PWD/release/docs
  }

!exists($$DDIR) {
    help_copy.commands += @echo "Creating Docs Directory: $$DDIR ($$EDIR)" $$escape_expand(\\n\\t)
    help_copy.commands += md $$DDIR $$escape_expand(\\n\\t)
  }
# replace forward-slashes

  DDIR ~= s,/,\\,g

  helpCopyCommands($$OTHER_FILES)

  help_copy.commands += $$MYFILECOPY
  help_copy.commands += @echo "Running qhelpgenerator" $$escape_expand(\\n\\t)
  help_copy.commands += $$[QT_INSTALL_BINS]\\qhelpgenerator $$DDIR\\docs.qhp -o $$DDIR\\docs.qch $$escape_expand(\\n\\t)
  help_copy.commands += @echo "Running qcollectiongenerator" $$escape_expand(\\n\\t)
  help_copy.commands += $$[QT_INSTALL_BINS]\\qcollectiongenerator $$DDIR\\docs.qhcp -o $$DDIR\\docs.qhc $$escape_expand(\\n\\t)
}

# OSX Instructions
macx {

 LIBS += -framework QtHelp

 DDIR = $$OUT_PWD/$$TARGET.app/Contents/MacOS/docs

 !exists($$DDIR) {
    help_copy.commands += @echo "Creating Docs Directory: $$DDIR" $$escape_expand(\\n\\t)
    help_copy.commands += mkdir -p $$DDIR $$escape_expand(\\n\\t)
  }

 helpCopyCommands($$OTHER_FILES)
 help_copy.commands += $$MYFILECOPY
 help_copy.commands += @echo "Running qhelpgenerator" $$escape_expand(\\n\\t)
 help_copy.commands += $$[QT_INSTALL_BINS]/qhelpgenerator $$DDIR/docs.qhp -o $$DDIR/docs.qch $$escape_expand(\\n\\t)
 help_copy.commands += @echo "Running qcollectiongenerator" $$escape_expand(\\n\\t)
 help_copy.commands += $$[QT_INSTALL_BINS]/qcollectiongenerator $$DDIR/docs.qhcp -o $$DDIR/docs.qhc $$escape_expand(\\n\\t)
}

Leave a Reply