2016-10-05 6 views
0

QTを初めて教えようとしています。QTクリエイター - 'QGraphicsScene'はタイプに名前を付けません

次のサンプル/チュートリアルの後、私はこのコードに着きました。

目的は、ログインを可能にする簡単なインターフェイスを作成することです。

マイエラー:

mainwindow.h:22: error: 'QGraphicsScene' does not name a type 
    QGraphicsScene *scene; 

私は解決策が、UIからオブジェクトを削除し、QGraphicsSceneをインスタンス化する際にthis代わりのui->graphicsViewを使用しての唯一の言及を発見していません。

私には何が欠けていますか?

ヘッダ/ mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QMainWindow> 
#include <QtCore> 
#include <QtGui> 

namespace Ui { 
class MainWindow; 
} 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    ~MainWindow(); 

private: 
    Ui::MainWindow *ui; 
    QGraphicsScene *scene; 
}; 

#endif // MAINWINDOW_H 

ソース/ mainwindow.cpp

#include "mainwindow.h" 
//#include "ui_mainwindow.h" 

MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent), 
    ui(new Ui::MainWindow) 
{ 
    ui->setupUi(this); 
    scene = new QGraphicsScene(ui->graphicsView); 
    scene->setSceneRect(ui->graphicsView->rect()); 
    ui->graphicsView->setScene(scene); 
    ui->graphicsView->setFixedSize(400,400); 
    QPixmap pixmap("res/logo/logo-black.png"); 
    scene->addPixmap(pixmap); 
    ui->graphicsView->show(); 
} 

MainWindow::~MainWindow() 
{ 
    delete ui; 
} 

ソース/ main.cppに

#include "mainwindow.h" 
#include <QApplication> 

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 
    MainWindow w; 
    w.show(); 

    return a.exec(); 
} 

フォーム/ mainwindows.ui

<?xml version="1.0" encoding="UTF-8"?> 
<ui version="4.0"> 
<class>MainWindow</class> 
<widget class="QMainWindow" name="MainWindow"> 
    <property name="geometry"> 
    <rect> 
    <x>0</x> 
    <y>0</y> 
    <width>283</width> 
    <height>415</height> 
    </rect> 
    </property> 
    <property name="windowTitle"> 
    <string>MainWindow</string> 
    </property> 
    <widget class="QWidget" name="centralWidget"> 
    <widget class="QLineEdit" name="lineEdit"> 
    <property name="geometry"> 
    <rect> 
     <x>120</x> 
     <y>130</y> 
     <width>141</width> 
     <height>22</height> 
    </rect> 
    </property> 
    </widget> 
    <widget class="QLineEdit" name="lineEdit_2"> 
    <property name="geometry"> 
    <rect> 
     <x>120</x> 
     <y>170</y> 
     <width>141</width> 
     <height>22</height> 
    </rect> 
    </property> 
    </widget> 
    <widget class="QPushButton" name="pushButton"> 
    <property name="geometry"> 
    <rect> 
     <x>90</x> 
     <y>250</y> 
     <width>91</width> 
     <height>31</height> 
    </rect> 
    </property> 
    <property name="text"> 
    <string>Login</string> 
    </property> 
    </widget> 
    <widget class="QCheckBox" name="checkBox"> 
    <property name="geometry"> 
    <rect> 
     <x>90</x> 
     <y>220</y> 
     <width>101</width> 
     <height>20</height> 
    </rect> 
    </property> 
    <property name="text"> 
    <string>Remeber Me</string> 
    </property> 
    </widget> 
    <widget class="QLabel" name="label"> 
    <property name="geometry"> 
    <rect> 
     <x>20</x> 
     <y>130</y> 
     <width>59</width> 
     <height>14</height> 
    </rect> 
    </property> 
    <property name="text"> 
    <string>Email</string> 
    </property> 
    </widget> 
    <widget class="QLabel" name="label_2"> 
    <property name="geometry"> 
    <rect> 
     <x>20</x> 
     <y>170</y> 
     <width>59</width> 
     <height>14</height> 
    </rect> 
    </property> 
    <property name="text"> 
    <string>Password</string> 
    </property> 
    </widget> 
    <widget class="QPushButton" name="pushButton_2"> 
    <property name="geometry"> 
    <rect> 
     <x>96</x> 
     <y>310</y> 
     <width>80</width> 
     <height>22</height> 
    </rect> 
    </property> 
    <property name="text"> 
    <string>Register</string> 
    </property> 
    </widget> 
    <widget class="QGraphicsView" name="graphicsView"> 
    <property name="geometry"> 
    <rect> 
     <x>80</x> 
     <y>0</y> 
     <width>121</width> 
     <height>111</height> 
    </rect> 
    </property> 
    <property name="autoFillBackground"> 
    <bool>false</bool> 
    </property> 
    </widget> 
    </widget> 
    <widget class="QMenuBar" name="menuBar"> 
    <property name="geometry"> 
    <rect> 
    <x>0</x> 
    <y>0</y> 
    <width>283</width> 
    <height>19</height> 
    </rect> 
    </property> 
    </widget> 
    <widget class="QToolBar" name="mainToolBar"> 
    <attribute name="toolBarArea"> 
    <enum>TopToolBarArea</enum> 
    </attribute> 
    <attribute name="toolBarBreak"> 
    <bool>false</bool> 
    </attribute> 
    </widget> 
    <widget class="QStatusBar" name="statusBar"/> 
</widget> 
<layoutdefault spacing="6" margin="11"/> 
<resources/> 
<connections/> 
</ui> 

UPDATE

  • アンコメント:私はこのように考えて、私のプロジェクトディレクトリにui_mainwindow.hを見ていない #include "ui_mainwindow.h"

Sources/mainwindow.cppで理由不要なインクルードです。documentation pageから見つかりHeaders/mainwindow.h

#include <QGraphicsScene>追加

  • - より多くの試み "私はこれを追加した場合、何が起こるか" のは、<QtGui><QGraphicsScene>

    が含まれていることを考えていましたありがとう

答えて

2

あなたが含める必要があります以下:あなたが必要なものも含めて、不要なヘッダを含めた、とされていないhere

0

を述べ

#include <QGraphicsScene> 

として。ウィジェットモジュールを使用するには、#include <QtWidgets>が必要です。 mainwindow.hファイルは、次のように開始されます。

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QtWidgets> 

namespace Ui { 
    ... 
関連する問題