1

I have the following problem. I have a file created with Qt Designer named inputwindow.ui. But when I want to use the objects created (for exemple couleurRadio) in the file inputwindow.cpp, it is said this name does not exist.

Instead, I have old names like RadioButton_2 and some objects are missing like ColorOrTexture. It seems that the file included ui_inputwindow.h in the cpp file was not updated from inputwindow.ui

Here are two screens to explain : .cpp : old names .ui

Thank you for your help !

Here is the code :

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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Choix de la texture qui s'appliquera sur l'objet&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Sur chaque polygone, la texture sera définie par une couleur unique&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Une image s'appliquera sur l'objet&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>

Edit : added the classe Scene

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

polimou
  • 21
  • 3
  • I've tested your code and I have not had a problem. You could share the code of the `Scene` class – eyllanesc Mar 14 '17 at 05:46
  • Have you tried to clean your project, run qMake, and recompile? – Venom Mar 14 '17 at 08:43
  • @eyllanesc done – polimou Mar 14 '17 at 12:28
  • @basslo yes, there are no changes – polimou Mar 14 '17 at 12:28
  • Ok! Run clean again, find out if the generated file "ui_inputwindow.h" is deleted, if not it has something to do with your project configuration. Try to delete it manually and see if it is generated at the same place. Maybe you changed your configuration after creating a first "ui_inputwindow.h" and it is taking the wrong one. – Venom Mar 14 '17 at 12:33
  • @basslo Thank you very much, the file "ui_inputwindow.h" was indeed not deleted by the cleaning. I don't know why. But if I delete it manually, it works – polimou Mar 14 '17 at 13:22
  • well, i guess the first files were generated next to your source code files and the other one (the one the project should use and was not using is next to your .exe). That's because the project configuration changed after the first creation ( switched two config release debug or other). It is important to parameter well your project so you don't have that kind of problem see my post in that link for more information : https://stackoverflow.com/questions/39587000/add-32-bit-versions-of-qt-5-7-on-a-64-bit-machine/39602290#39602290. P.S : i'm on windows. But i think it is the same at other Os. – Venom Mar 14 '17 at 13:33

0 Answers0