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
這段代碼有什麼問題?