了解了为什么Qt Creator打开.ui.qml文件直接跳转到了设计器



  • 调试了超过两天,Qt Creator的调试实在是太难了。Windows下MSVC无法调用调试器,MinGW太卡,而且出现了段错误(SIGSEV),最后还是Linux下GDB调试成功。后面发现是:
    D:\qt-creator-opensource-src-3.5.1\src\plugins\qmljseditor\QmlJSEditor.cpp中的1038行附近:

     if (textDocument() && textDocument()->mimeType() == QLatin1String(QmlJSTools::Constants::QMLUI_MIMETYPE))
            alwaysPreferDesignMode = true;
    

    导致一开始载入文档的时候,就跳入了设计器中。



  • 后面终于调试发现了原因,在这个文件中:

    Dialect ModelManagerInterface::guessLanguageOfFile(const QString &fileName)
    {
        QHash<QString, Dialect> lMapping;
        if (instance())
            lMapping = instance()->languageForSuffix();
        else
            lMapping = defaultLanguageMapping();
        const QFileInfo info(fileName);
        QString fileSuffix = info.suffix();
    
        /*
         * I was reluctant to use complete suffix in all cases, because it is a huge
         * change in behaivour. But in case of .qml this should be safe.
         */
    
        if (fileSuffix == QLatin1String("qml"))
            fileSuffix = info.completeSuffix();// 在这里,.ai.qml被检测出是fileSuffix = "ai.qml",在hash中找不到
    
        return lMapping.value(fileSuffix, Dialect::NoLanguage);
    }
    

    接下来想个办法怎么让它变成认识的QML文件呢?



  • 后面看了很多源码,发现怎么做也不好在不修改Qt Creator中qmljstools中ModelManager::languageForSuffix()函数的情况下,使其支持.ai.qml文件。而且这个接口也不能暴露出来,所以这真的不好办的样子。


Log in to reply
 

走马观花

最近的回复

  • 离线安装包的下载地址是:coding源github源

    read more
  • 看到过很多代码都有用这个

    read more
  • 做得还不错的嘛。希望继续呢。

    read more
  • 首先我看到的就是option选项。这个选项在cmake中的文档是这样的:

    Now let us consider making the MathFunctions library optional. In this tutorial there really isn’t any reason to do so, but with larger libraries or libraries that rely on third party code you might want to. The first step is to add an option to the top level CMakeLists file.

    # should we use our own math functions? option (USE_MYMATH "Use tutorial provided math implementation" ON)

    This will show up in the CMake GUI with a default value of ON that the user can change as desired. This setting will be stored in the cache so that the user does not need to keep setting it each time they run CMake on this project. The next change is to make the build and linking of the MathFunctions library conditional. To do this we change the end of the top level CMakeLists file to look like the following:

    # add the MathFunctions library? # if (USE_MYMATH) include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions") add_subdirectory (MathFunctions) set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions) endif (USE_MYMATH) # add the executable add_executable (Tutorial tutorial.cxx) target_link_libraries (Tutorial ${EXTRA_LIBS}) 参考来源:这里

    在我看来,cmake中的option命令更像是一个宏,规定了是否定义这个宏以及这个宏所带来的连锁反应。option规定的这个宏,通过ON的设定来表示是否定义。

    read more

关注我们

微博
QQ群