快速2用控制台打印

时间:2015-11-12 15:59:34

标签: qt qml qtquick2

我无法弄清楚如何在qt快速应用程序中使用console.log进行打印。

我有这个.pro文件:

TEMPLATE = app

QT += qml quick
CONFIG += c++11
CONFIG += console

SOURCES += main.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Default rules for deployment.
include(deployment.pri)

这是main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[]) {
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

这是main.qml:

import QtQuick 2.5
import QtQuick.Window 2.0

Window {
   visible: true
   Text {
      anchors.centerIn: parent
      text: "Hello World"
   }
   Component.onCompleted: console.log("foo")
}

为什么不打印“foo”?

1 个答案:

答案 0 :(得分:4)

解决了这个问题是因为Fedora在/etc/xdg/QtProject/qtlogging.ini中有* .debug = false,这会阻止打印消息。要“解决”这个就足以用这个内容创建文件〜/ .config / QtProject / qtlogging.ini:

[Rules]
default=true