2016-12-06 315 views
0

我有錯誤C2227麻煩,這裏是我的代碼錯誤C2227:左「 - >寬度」必須指向類/結構/聯合/泛型類型,光線投射渲染

我不知道如何有存取權限從音量 - > voxel->寬度MyWindow,我必須得到一個寬度的音量數據。

我編輯了一篇文章。我在Volume類型中創建了一個指針,但它不起作用。

MyWindow.cpp

#include "MainWindow.h" 

#include <QFileDialog> 

#include <QPainter> 
#include "Volume.h" 


MainWindow::MainWindow(QWidget *parent) 
    : QMainWindow(parent), m_Volume(0), m_VectorField(0) 
{ 
    m_Ui = new Ui_MainWindow(); 
    m_Ui->setupUi(this); 

    connect(m_Ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFileAction())); 
    connect(m_Ui->actionClose, SIGNAL(triggered()), this, SLOT(closeAction())); 






    float width = m_Ui->label->width(); 
    float height = m_Ui->label->height(); 




(float i = 0; i < m_Volume->voxel->width; i++) // HERE IS ERROR 
    { 
     m_Ui->label->width(); 
    } 

    QPixmap map(width, height); 
    map.fill(QColor(255, 0, 0, 0)); 








} 

volume.h

// Voxel 
//------------------------------------------------------------------------------------------------- 

class Voxel 
{ 
    public: 

     Voxel(); 
     Voxel(const Voxel &other); 
     Voxel(const float value); 

     ~Voxel(); 


     // VOXEL VALUE 

     void     setValue(const float value); 
     const float    getValue() const; 


     // OPERATORS 

     const bool    operator==(const Voxel &other) const; 
     const bool    operator!=(const Voxel &other) const; 
     const bool    operator>(const Voxel &other) const; 
     const bool    operator>=(const Voxel &other) const; 
     const bool    operator<(const Voxel &other) const; 
     const bool    operator<=(const Voxel &other) const; 

     const Voxel    operator+(const Voxel &other) const; 
     const Voxel    operator-(const Voxel &other) const; 
     const Voxel    operator*(const float &value) const; 
     const Voxel    operator/(const float &value) const; 

     const Voxel&   operator+=(const Voxel &other); 
     const Voxel&   operator-=(const Voxel &other); 
     const Voxel&   operator*=(const float &value); 
     const Voxel&   operator/=(const float &value); 


    private: 

     float     m_Value; 

}; 


//------------------------------------------------------------------------------------------------- 
// Volume 
//------------------------------------------------------------------------------------------------- 

class Volume 
{ 

    public: 

     Volume(); 
     ~Volume(); 


     // VOLUME DATA 

     const Voxel&   voxel(const int i) const; 
     const Voxel&   voxel(const int x, const int y, const int z) const; 
     const Voxel*   voxels() const; 

     const int    width() const; 
     const int    height() const; 
     const int    depth() const; 

     const int    size() const; 

     bool     loadFromFile(QString filename, QProgressBar* progressBar); 


    private: 

     std::vector<Voxel>  m_Voxels; 

     int      m_Width; 
     int      m_Height; 
     int      m_Depth; 

     int      m_Size; 

}; 
+3

請將[你的問題]寫成[mcve]。這隻需要聲明m_Volume,賦值給它,並嘗試訪問寬度。我們還需要所有相關類型的完整定義。 –

+0

我有,編輯過一個帖子 –

+0

Voxel沒有寬度作爲成員。卷的確如此。所以不應該是'm_Volume-> width()'而不是'm_Volume-> voxel-> width'? – drescherjm

回答

-1
m_Ui->label->width(); 

我正在拉貝的寬度,用於映射。

我這樣做了主窗口的::主窗口()

但是我有,誤差太大。

void MainWindow::paintEvent(QPaintEvent *) 
{ 
    QPainter painter(this); 

    float width = m_Ui->label->width(); 
    float height = m_Ui->label->height(); 


    QPixmap map(width, height); 
    map.fill(QColor(255, 0, 0, 0)); 





    for (int i = 0; i < m_Volume->width(); i++) 
    { 
     for (int j = 0; i < m_Volume->height(); j++) 
     { 
      for (int k = 0; i < m_Volume->depth(); k++) 
      { 
       m_Ui->label->setPixmap(map); 
      } 
     } 
    } 


} 
+0

這不是你的問題的答案。請改爲編輯您的問題並添加附加信息。 – drescherjm

+0

也可以請你檢查或顯示你的聲明的變量m_Volume我認爲它不是一個指針。我可能錯了,並且在修改代碼後告訴你是否仍然出現c2227編譯器錯誤以及在哪一行。 –

+0

m_FileType.type = VOLUME; \t \t \t m_Volume = new Volume(); –

相關問題