1

我在 ~/Library/Application Support (QStandardPaths::AppDataLocation[0]) 中编写我的应用程序日志,如果我从 Qt Creator 启动我的应用程序,一切顺利。使用pkgbuildproductbuild打包应用程序后,使用我的开发人员 ID 应用程序(用于 codesign)和开发人员 ID 安装程序(用于 productbuild)对应用程序进行签名,当我将其安装在我的机器上时,具有管理员权限,不会生成日志文件(目录树它是生成的)。我正在使用 std::ofstream 将 QByteArray 中的消息写入文件。另外,我正在使用qInstallMessageHandler

知道如何让它工作吗?我需要在productbuild 中向我的Distribution.xml添加一些内容吗?我需要在打包步骤中添加更多权利吗?

这是我正在使用的处理程序

void tracesOutputHandler(QtMsgType type, const QMessageLogContext& context, const QString & msg)
{
    std::cout << "This is called" << std::endl;
    QString txt;
    switch (type) {
    case QtDebugMsg:
        txt = QString("Debug: %1").arg(msg);
        break;
    case QtWarningMsg:
        txt = QString("Warning: %1").arg(msg);
        break;
    case QtCriticalMsg:
        txt = QString("Critical: %1").arg(msg);
        break;
    case QtFatalMsg:
        txt = QString("Fatal: %1").arg(msg);
        break;
    }

    // log_name here is well-formed.
    QFile outFile(log_name);
    if (outFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
        QTextStream ts(&outFile);
        ts << txt << endl;
    } else {
        qDebug() << Q_FUNC_INFO << "Cannot open in log file";
    }
}

这被称为消息出现在 QtCreator 执行中。

此外,只需添加该应用程序不是沙盒。

编辑:经过大量测试,我认为当应用程序开始双击应用程序图标时,没有调用 MessageHandler tracesOutputHandler 。

4

0 回答 0