使用visualstudio2010编译qt项目时出错

errors in compiling my qt project using visual studio 2010

本文关键字:出错 项目 qt visualstudio2010 编译 使用      更新时间:2023-10-16

我的qt项目出现问题。我以前使用qtcreator,所以我所做的只是复制我的文件,在visualstudio中创建一个新项目并编译。这就是问题产生的地方。我使用visualstudio2010ultimate和qt5.5.1制作msvc2010。所有插件都是动态加载的,qtaddin用于visualstudio。

这是我的头文件

denso_app.h

#ifndef DENSO_APP_H
#define DENSO_APP_H
#include <QtWidgets/QMainWindow>
#include <QtSql>
#include <QDebug>
#include <QFileInfo>
#include "ui_denso_app.h"
class denso_app : public QMainWindow
{
Q_OBJECT
public:
denso_app(QWidget *parent = 0);
~denso_app();
private:
Ui::denso_appClass ui;
};
#endif // DENSO_APP_H

这是我的cpp文件

denso_app.cpp

                #include "denso_app.h"
            denso_app::denso_app(QWidget *parent)
                : QMainWindow(parent)
            {
                ui.setupUi(this);
                QSqlDatabase mydb = QSqlDatabase::addDatabase("QSQLITE");
                mydb.setDatabaseName("C:/Users/Youniquex/Documents/Visual Studio 2010/Projects/denso_app");
                if(mydb.open())
                {
                    ui -> label_dbstat -> setText("Failed to open the database");
                }
                else
                    ui -> label_dbstat ->setText("Database Connected...");
            }
            denso_app::~denso_app()
            {
            }

这是我的ui文件。

denso_app.ui

        <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>denso_appClass</class>
     <widget class="QMainWindow" name="denso_appClass">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>600</width>
        <height>400</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>denso_app</string>
      </property>
      <widget class="QWidget" name="centralWidget">
       <widget class="QGroupBox" name="groupBox">
        <property name="geometry">
         <rect>
          <x>150</x>
          <y>100</y>
          <width>411</width>
          <height>171</height>
         </rect>
        </property>
        <property name="font">
         <font>
          <pointsize>10</pointsize>
          <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
        <property name="title">
         <string>DensoApp</string>
        </property>
        <widget class="QPushButton" name="pushButton">
         <property name="geometry">
          <rect>
           <x>150</x>
           <y>140</y>
           <width>75</width>
           <height>23</height>
          </rect>
         </property>
         <property name="text">
          <string>Login</string>
         </property>
        </widget>
        <widget class="QWidget" name="layoutWidget">
         <property name="geometry">
          <rect>
           <x>10</x>
           <y>30</y>
           <width>351</width>
           <height>27</height>
          </rect>
         </property>
         <layout class="QHBoxLayout" name="horizontalLayout">
          <item>
           <widget class="QLabel" name="label_username">
            <property name="text">
             <string>Username</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QLineEdit" name="lineEdit"/>
          </item>
         </layout>
        </widget>
        <widget class="QWidget" name="layoutWidget">
         <property name="geometry">
          <rect>
           <x>10</x>
           <y>70</y>
           <width>351</width>
           <height>29</height>
          </rect>
         </property>
         <layout class="QHBoxLayout" name="horizontalLayout_2">
          <item>
           <widget class="QLabel" name="label_password">
            <property name="text">
             <string>Password</string>
            </property>
           </widget>
          </item>
          <item>
           <widget class="QLineEdit" name="lineEdit_2"/>
          </item>
         </layout>
        </widget>
       </widget>
       <widget class="QLabel" name="label_3">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>-20</y>
          <width>101</width>
          <height>101</height>
         </rect>
        </property>
        <property name="text">
         <string/>
        </property>
        <property name="pixmap">
         <pixmap>E:/DENSO/pictures/denso1.png</pixmap>
        </property>
       </widget>
       <widget class="QLabel" name="label_4">
        <property name="geometry">
         <rect>
          <x>100</x>
          <y>10</y>
          <width>431</width>
          <height>31</height>
         </rect>
        </property>
        <property name="font">
         <font>
          <pointsize>18</pointsize>
         </font>
        </property>
        <property name="autoFillBackground">
         <bool>false</bool>
        </property>
        <property name="text">
         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; color:#ffffff;BACKGROUND:RED;&quot;&gt;DENSO MOTOR SPARES (T) LTD.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_7">
        <property name="geometry">
         <rect>
          <x>110</x>
          <y>50</y>
          <width>441</width>
          <height>16</height>
         </rect>
        </property>
        <property name="font">
         <font>
          <pointsize>9</pointsize>
         </font>
        </property>
        <property name="text">
         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-style:italic; color:#365f91;&quot;&gt;Dealers in all types of Toyota, Nissan, Ford, Subaru, and Suzuki Genuine Parts&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_db">
        <property name="geometry">
         <rect>
          <x>20</x>
          <y>290</y>
          <width>101</width>
          <height>29</height>
         </rect>
        </property>
        <property name="font">
         <font>
          <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
        <property name="text">
         <string>Database Status:</string>
        </property>
       </widget>
       <widget class="QLabel" name="label_dbstat">
        <property name="geometry">
         <rect>
          <x>130</x>
          <y>290</y>
          <width>251</width>
          <height>29</height>
         </rect>
        </property>
        <property name="font">
         <font>
          <weight>75</weight>
          <bold>true</bold>
         </font>
        </property>
        <property name="text">
         <string>Status</string>
        </property>
       </widget>
      </widget>
      <widget class="QMenuBar" name="menuBar">
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>600</width>
         <height>21</height>
        </rect>
       </property>
       <widget class="QMenu" name="menuDensoApp">
        <property name="title">
         <string>DensoApp</string>
        </property>
       </widget>
       <widget class="QMenu" name="menuHelp">
        <property name="title">
         <string>Help</string>
        </property>
       </widget>
       <addaction name="menuDensoApp"/>
       <addaction name="menuHelp"/>
      </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>
      <include location="denso_app.qrc"/>
     </resources>
     <connections/>
    </ui>

下面是我在编译上述项目时遇到的错误。

     Warning    1   warning : The name 'layoutWidget' (QWidget) is already in use, defaulting to 'layoutWidget1'.   C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.ui   1   1   denso_app
     Warning    2   warning : No resources in 'C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.qrc'. C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appRCC    denso_app
     Error  3   error C2819: type 'Ui::denso_appClass' does not have an overloaded member 'operator ->' C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  13  1   denso_app
     Error  4   error C2232: '->Ui_denso_appClass::label_dbstat' : left operand has 'class' type, use '.'   C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  13  1   denso_app
     Error  5   error C2227: left of '->setText' must point to class/struct/union/generic type  C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  13  1   denso_app
     Error  6   error C2819: type 'Ui::denso_appClass' does not have an overloaded member 'operator ->' C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  17  1   denso_app
     Error  7   error C2232: '->Ui_denso_appClass::label_dbstat' : left operand has 'class' type, use '.'   C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  17  1   denso_app
     Error  8   error C2227: left of '->setText' must point to class/struct/union/generic type  C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  17  1   denso_app

我试过下列。。。我改变了指针,在denso_app.cpp中使用了*指针,就像这个一样

            if(mydb.open())
            {
                ui * label_dbstat * setText("Failed to open the database");
            }
            else
                ui * label_dbstat * setText("Database Connected...");

然后我再次得到以下错误

    Error   1   error C2065: 'label_dbstat' : undeclared identifier C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  13  1   denso_app
    Error   2   error C3861: 'setText': identifier not found    C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  13  1   denso_app
    Error   3   error C2065: 'label_dbstat' : undeclared identifier C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  17  1   denso_app
    Error   4   error C3861: 'setText': identifier not found    C:UsersYouniquexDocumentsVisual Studio 2010Projectsdenso_appdenso_appdenso_app.cpp  17  1   denso_app
        5   IntelliSense: identifier "label_dbstat" is undefined            c:usersyouniquexdocumentsvisual studio 2010projectsdenso_appdenso_appdenso_app.cpp  13  8   denso_app
        6   IntelliSense: identifier "setText" is undefined c:usersyouniquexdocumentsvisual studio 2010projectsdenso_appdenso_appdenso_app.cpp  13  23  denso_app
        7   IntelliSense: identifier "label_dbstat" is undefined    c:usersyouniquexdocumentsvisual studio 2010projectsdenso_appdenso_appdenso_app.cpp  17  8   denso_app
        8   IntelliSense: identifier "setText" is undefined c:usersyouniquexdocumentsvisual studio 2010projectsdenso_appdenso_appdenso_app.cpp  17  23  denso_app

我真的被困在这里,我真的不知道如何解决这个问题。非常感谢您的回答。谢谢,祝你一切顺利。

问候。。。

好的,谢谢你查看或回复我的问题。。。我在这里找到了问题的答案。。。如果像我这样的初学者遇到和我一样的问题,那么答案真的很简单,正如@Ulrich Eckhardt所说,下面是如何解决这个问题的链接。。。

创建GUI/界面:使用Visual Studio 2010和QT