1
我想显示一个非常简单和短名单的国家使用QStringListModel
和QListView
。但是当我编译它时,我会看到一个空白的窗口。QListView不能在Mac OS中显示
这是我的类代码:
#include "FenPrincipale.h"
FenPrincipale::FenPrincipale()
{
QVBoxLayout *layout = new QVBoxLayout;
QStringList listePays;
listePays << "France" << "Espagne" << "Italie" << "Portugal" << "Suisse";
QStringListModel *modele = new QStringListModel(listePays);
QListView *vue = new QListView;
vue->setModel(modele);
layout->addWidget(vue);
setLayout(layout);
}
标题:
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QMainWindow>
#include <QVBoxLayout>
#include <QStringList>
#include <QListView>
#include <QStringListModel>
class FenPrincipale : public QMainWindow
{
Q_OBJECT
public:
FenPrincipale();
};
#endif // FENPRINCIPALE_H
主要:
#include "FenPrincipale.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FenPrincipale w;
w.show();
return a.exec();
}
的pro
文件:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = utilisationModeleSimple
TEMPLATE = app
SOURCES += main.cpp\
FenPrincipale.cpp
HEADERS += FenPrincipale.h
FORMS += FenPrincipale.ui
我目前使用基于Qt 5.4.0(Clang 6.0(Apple),64位)的Qt Creator 3.3.0; OS X Yosemite 10.10.2
这段代码有什么问题?