Qt アプリケーション全体の書式設定のために CSS ファイルを読み込もうとしています。現在、ビルドしたexeファイルと同じフォルダーに「stylesheet.css」ファイルがあります(デバッグとリリースの両方)。ただし、プログラムを実行してもエラーは発生せず、単に「test:」が出力されるため、明らかにファイルが見つからないか、正しく読み取れていないのでしょうか?
それがばかげた間違いなら許してください-私はQtとC ++の両方にかなり慣れていません。
#include "mainwindow.h"
#include "qfile.h"
#include "qtextstream.h"
#include <QApplication>
#include <iostream>
int main(int argc, char *argv[])
{
QApplication program(argc, argv);
QFile styleFile("stylesheet.css");
styleFile.open(QIODevice::ReadOnly);
QTextStream textStream(&styleFile);
QString styleSheet = textStream.readAll();
styleFile.close();
program.setStyleSheet(styleSheet);
std::cout << "test: " << styleSheet.toStdString() << std::endl;
MainWindow w;
w.showMaximized();
return program.exec();
}