使用visualstudio2010编译qt项目时出错
errors in compiling my qt project using visual studio 2010
我的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><html><head/><body><p align="center"><span style=" font-weight:600; color:#ffffff;BACKGROUND:RED;">DENSO MOTOR SPARES (T) LTD.</span></p></body></html></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><html><head/><body><p align="center"><span style=" font-style:italic; color:#365f91;">Dealers in all types of Toyota, Nissan, Ford, Subaru, and Suzuki Genuine Parts</span></p></body></html></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
相关文章:
- 当我尝试通过 mingw 使用 CMake 和 SFML 库编译项目时出错
- 如何使用我构建的库,而不会从源代码出错,但不为我自己的项目编译?
- Flex/Bison:构建示例项目以生成 CPP 时出错
- 将项目导入 Android Studio 后出错
- 将 Dr. Memory 与 Visual Studio 项目配合使用时出错:缺少应用程序所需的库
- 使用 C++Builder 项目读取字符串中的文件时出错
- 在 Visual Studio 2015 中生成 vsal 项目时出错
- 创建新的 Visual Studio c++ 项目时出错
- 编译包含 CPLEX 工具的项目时出错
- CMake 和/或在为项目添加提升时出错
- 链接 gtest 项目时出错
- iOS:在真实设备上运行项目时出错
- 在qmake项目中编译sqlite时出错
- LNK1104将Boost库添加到Qt项目时出错
- 仅在从命令行构建Qt项目时出错
- 运行调试库项目时发布库出错
- Qt项目qmake在构建上出错
- 将VC++项目从VS2010升级到VS2012时出错
- 在c++项目中包含dlib库时出错
- 使用CMake编译OpenCV项目时出错