我有以下问题。我有一个用Qt Designer创建的文件,名为inputwindow.ui。但是当我想在inputwindow.cpp文件中使用创建的对象(例如couleurRadio
)时,可以说这个名称不存在。
相反,我有RadioButton_2
之类的旧名称,而ColorOrTexture
则缺少一些对象。似乎cpp文件中包含ui_inputwindow.h
的文件未从inputwindow.ui
感谢您的帮助!
以下是代码:
inputwindow.cpp
#include "inputwindow.h"
#include "ui_inputwindow.h"
#include <QButtonGroup>
#include <QObject>
#include "scene.h"
InputWindow::InputWindow(Scene* scene, QWidget *parent) :
QDialog(parent),
ui(new Ui::InputWindow)
{
ui->setupUi(this);
group = new QButtonGroup(this);
group->addButton(ui->radioButton, 0);
group->addButton(ui->radioButton_2, 1);
connect(ui->group, SIGNAL(buttonClicked(int)), scene, SLOT(setColorOrTextureFromGUI(int)));
}
InputWindow::~InputWindow()
{
delete ui;
}
inputwindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InputWindow</class>
<widget class="QDialog" name="InputWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>256</height>
</rect>
</property>
<property name="windowTitle">
<string>Création de l'objet</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>17</height>
</size>
</property>
<property name="text">
<string>Dans cet assistant, vous défnirez une liste de points, vous les relierez pour créer des polygones, puis vous appliquerez une texture pour créer votre objet.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="toolTip">
<string><html><head/><body><p>Choix de la texture qui s'appliquera sur l'objet</p></body></html></string>
</property>
<property name="title">
<string>Type de texture</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="couleurRadio">
<property name="toolTip">
<string><html><head/><body><p>Sur chaque polygone, la texture sera définie par une couleur unique</p></body></html></string>
</property>
<property name="accessibleName">
<string>couleurRadio</string>
</property>
<property name="text">
<string>Monochrome</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">colorOrTexture</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="imageRadio">
<property name="toolTip">
<string extracomment="sdsdsdsdsd"><html><head/><body><p>Une image s'appliquera sur l'objet</p></body></html></string>
</property>
<property name="text">
<string>Image</string>
</property>
<attribute name="buttonGroup">
<string notr="true">colorOrTexture</string>
</attribute>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Choix du polygone</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="triangleRadio">
<property name="text">
<string>Triangle</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="QuadrilatereRadio">
<property name="text">
<string>Quadrilatère</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="PentagoneRadio">
<property name="text">
<string>Pentagone</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>InputWindow</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>236</x>
<y>246</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>174</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>InputWindow</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>304</x>
<y>246</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>174</y>
</hint>
</hints>
</connection>
</connections>
<buttongroups>
<buttongroup name="colorOrTexture">
<property name="exclusive">
<bool>true</bool>
</property>
</buttongroup>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>
编辑:添加了classe场景
Scene.h
#ifndef SCENE_H
#define SCENE_H
#include "light.h"
#include "svertex.h"
#include <QWidget>
#include "QAbstractButton"
#include <QObject>
#include <string>
#include <vector>
using namespace std;
enum colorOrTexture {color, texture};
inline std::istream & operator>>(std::istream & str, colorOrTexture & v) {
unsigned int a_colorOrTexture = 0;
if (str >> a_colorOrTexture)
v = static_cast<colorOrTexture>(a_colorOrTexture);
return str;
}
class Scene : public QObject
{
Q_OBJECT
protected:
//Precise if we use simple colors or if we apply textures on items
colorOrTexture mColor_or_texture;
//the number and list of vertices
int mVertexNumber;
vector<SVertex> mVertexList;
//the number of edges of the polygons (triangle ? rectangle ?)
int mPolygonType;
//the number and list of polygons.
int mIndicesSize;
vector<unsigned int> mIndices;
//The location of the observer
SVertex* mObs;
//the number and list of lights
int mLightNumber;
vector<Light> mLightList;
public:
//ask the user with a GUI the caracteristics of the scene
Scene();
//parse a file to get the caracteritics of the scene
Scene(string fileName);
//export the actual scene in a file
//void generate_file(QString fichier);
colorOrTexture getColor_or_texture();
void setColor_or_texture(colorOrTexture _Color_or_texture);
int getVertexNumber();
void setVertexNumber(int _VertexNumber);
vector<SVertex> getVertexList();
void setVertexList(vector<SVertex> _VertexList);
int getIndicesSize();
void setIndicesSize(int _IndicesSize);
vector<unsigned int> getIndices();
void setIndices(vector<unsigned int> _Indices);
int getPolygonType();
void setPolygonType(int _PolygonType);
SVertex* getObs();
void setObs(SVertex* _Obs);
virtual ~Scene();
public slots:
void setColorOrTextureFromGUI(int id);
};
#endif // SCENE_H
Scene.cpp
#include "scene.h"
#include "inputwindow.h"
#include "addpointswindow.h"
#include "addobs.h"
#include "addlights.h"
#include <fstream>
#include <iostream>
using namespace std;
Scene::Scene()
{
InputWindow window(this);
int introductionAccepted = window.exec();
if (introductionAccepted == QDialog::Accepted)
{
AddObs obsWindow;
int obsDefinitionAccepted = obsWindow.exec();
if (obsDefinitionAccepted == QDialog::Accepted)
{
AddPointsWindow pointsWindow;
int pointsWindowAccepted = pointsWindow.exec();
if (pointsWindowAccepted == QDialog::Accepted)
{
AddLights lightsWindow;
int lightsWindowAccepted = lightsWindow.exec();
if (lightsWindowAccepted == QDialog::Accepted)
{
//define scene
}
}
}
}
}
Scene::Scene(string fileName)
{
//ifstream fileStream(fileName, ios::in);
ifstream fileStream(fileName);
if(!fileStream)
{
//exception
}
int tmp;
fileStream >> tmp;
if (0 == tmp)
{mColor_or_texture = color;}
else
{mColor_or_texture = texture;
}
fileStream >> mVertexNumber;
vector<SVertex>::iterator vertexIterator;
mVertexList.resize(mVertexNumber);
for (vertexIterator = mVertexList.begin() ; vertexIterator != mVertexList.end() ; vertexIterator++ )
{
(*vertexIterator) = SVertexFromStream(fileStream);
}
// Loading polygon Type
fileStream >> mPolygonType;
// Loading Indices list, starting with size
fileStream >> mIndicesSize;
mIndices.resize(mIndicesSize);
vector<unsigned int>::iterator indexInterator;
for (indexInterator = mIndices.begin() ; indexInterator != mIndices.end() ; indexInterator++ )
{
fileStream >> (*indexInterator);
}
SVertex obs = SVertexFromStream(fileStream);
mObs = &(obs);
/* fileStream >> mLightNumber;
vector<Light>::iterator it3;
for (it3 = mLightList.begin() ; it3 != mLightList.end() ; it3++ )
{
(*it3) = Light(fileStream);
}
*/
}
Scene::~Scene()
{
}
colorOrTexture Scene::getColor_or_texture(){
return mColor_or_texture;
}
void Scene::setColor_or_texture(colorOrTexture _Color_or_texture){
mColor_or_texture = _Color_or_texture;
}
void Scene::setColorOrTextureFromGUI(int id)
{
mColor_or_texture = (id == 0) ? color : texture;
cout << "slot" << endl;
}
int Scene::getVertexNumber(){
return mVertexNumber;
}
void Scene::setVertexNumber(int _VertexNumber){
mVertexNumber = _VertexNumber;
}
vector<SVertex> Scene::getVertexList(){
return mVertexList;
}
void Scene::setVertexList(vector<SVertex> _VertexList){
mVertexList = _VertexList;
}
int Scene::getIndicesSize(){
return mIndicesSize;
}
void Scene::setIndicesSize(int _IndicesSize){
mIndicesSize = _IndicesSize;
}
vector<unsigned int> Scene::getIndices(){
return mIndices;
}
void Scene::setIndices(vector<unsigned int> _Indices){
mIndices = _Indices;
}
int Scene::getPolygonType(){
return mPolygonType;
}
void Scene::setPolygonType(int _PolygonType){
mPolygonType = _PolygonType;
}
SVertex* Scene::getObs(){
return mObs;
}
void Scene::setObs(SVertex* _Obs){
mObs = _Obs ;
}
Qt 5.5.1 Qt Creator 3.5.1