简体   繁体   中英

Open second window in Qt

I am trying to compile my code written in C++ , using Qt Creator . I am trying to create second window which will appear after click to menu item in main window and this window should have separate .ui file. But during compilation I get this error :

/home/martin/Code/C++/Map_generator/map_generator/preferenceswindow.cpp:4: error: prototype for 'Ui::PreferencesWindow::PreferencesWindow(QWidget*)' does not match any in class 'Ui::PreferencesWindow'
 Ui::PreferencesWindow::PreferencesWindow(QWidget *parent)
 ^

/home/bo/Code/C++/Map_generator/build-map_generator-Desktop-Debug/ui_preferenceswindow.h:88: error: candidates are: constexpr Ui::PreferencesWindow::PreferencesWindow(Ui::PreferencesWindow&&)
     class PreferencesWindow: public Ui_PreferencesWindow {};
           ^

What could be wrong?

preferenceswindow.h

#ifndef PREFERENCESWINDOW_H
#define PREFERENCESWINDOW_H

#include <QWidget>

namespace Ui
{
    class PreferencesWindow;
}

class PreferencesWindow : public QWidget
{
    Q_OBJECT
public:
    explicit PreferencesWindow(QWidget *parent = 0);

signals:

//public Q_SLOTS:
private:
    PreferencesWindow *uip;
};    
#endif // PREFERENCESWINDOW_H

preferenceswindow.cpp

#include "preferenceswindow.h"
#include "ui_preferenceswindow.h"

Ui::PreferencesWindow::PreferencesWindow(QWidget *parent)
    :QWidget(parent), uip(new Ui::PreferencesWindow)
{
    uip->setupUi(this);
}

preferenceswindow.ui file

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>PreferencesWindow</class>
 <widget class="QWidget" name="PreferencesWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>326</width>
    <height>159</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <widget class="QPushButton" name="pushButton">
   <property name="geometry">
    <rect>
     <x>200</x>
     <y>100</y>
     <width>99</width>
     <height>27</height>
    </rect>
   </property>
   <property name="text">
    <string>Save</string>
   </property>
  </widget>
  <widget class="QSpinBox" name="spinBox">
   <property name="geometry">
    <rect>
     <x>90</x>
     <y>100</y>
     <width>81</width>
     <height>27</height>
    </rect>
   </property>
   <property name="minimum">
    <number>1</number>
   </property>
   <property name="maximum">
    <number>200</number>
   </property>
   <property name="value">
    <number>15</number>
   </property>
  </widget>
  <widget class="QSpinBox" name="spinBox_2">
   <property name="geometry">
    <rect>
     <x>90</x>
     <y>20</y>
     <width>81</width>
     <height>27</height>
    </rect>
   </property>
   <property name="minimum">
    <number>1</number>
   </property>
   <property name="maximum">
    <number>1000</number>
   </property>
   <property name="value">
    <number>100</number>
   </property>
  </widget>
  <widget class="QSpinBox" name="spinBox_3">
   <property name="geometry">
    <rect>
     <x>90</x>
     <y>60</y>
     <width>81</width>
     <height>27</height>
    </rect>
   </property>
   <property name="minimum">
    <number>1</number>
   </property>
   <property name="maximum">
    <number>1000</number>
   </property>
   <property name="value">
    <number>60</number>
   </property>
  </widget>
  <widget class="QLabel" name="label">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>30</y>
     <width>67</width>
     <height>17</height>
    </rect>
   </property>
   <property name="text">
    <string>Columns</string>
   </property>
  </widget>
  <widget class="QLabel" name="label_2">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>70</y>
     <width>67</width>
     <height>17</height>
    </rect>
   </property>
   <property name="text">
    <string>Rows</string>
   </property>
  </widget>
  <widget class="QLabel" name="label_3">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>110</y>
     <width>67</width>
     <height>17</height>
    </rect>
   </property>
   <property name="text">
    <string>Grid Size</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

Your uip variable is declared as PreferencesWindow , when you want it to be declared as Ui::PreferencesWindow :

private:
    PreferencesWindow *uip;

change it to

private:
    Ui::PreferencesWindow *uip;

You are also defining a Ui::PreferencesWindow constructor in preferenceswindow.cpp . This is not what you want to do. You want to define PreferencesWindow constructor there. Like this:

PreferencesWindow::PreferencesWindow(QWidget *parent)
    :QWidget(parent), uip(new Ui::PreferencesWindow)
{
    uip->setupUi(this);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM