QT 5.0 Project issue
-
Hi ,
I am new to Qt . I am trying to run the project given through link :
http://qt-project.org/doc/qt-5.0/qtdoc/gettingstartedqt.html
However While buiding the project i am facing the below error :
- C:\Users\acer\Documents\Qt5.0\notepad\main.cpp:6:
bq. error: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'bq.
- C:\Users\acer\Documents\Qt5.0\notepad\notepad.cpp:8:
bq. error: undefined reference to `_imp___ZN11QMainWindowC2EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
Please let me know what may be the root cause for the same .
Thanks
-
These are the below codes :
- main.cpp
@ #include "notepad.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
notepad w;
w.show();return a.exec();
}@
2) notepad.cpp
@
#include "notepad.h"
#include "ui_notepad.h"
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>notepad::notepad(QWidget *parent) : QMainWindow(parent), ui(new Ui::notepad)
{
ui->setupUi(this);
}notepad::~notepad()
{
delete ui;
}void notepad::on_quitbutton_clicked()
{
qApp->quit();
}void notepad::on_actionOpen_2_triggered()
{QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QString(),tr("Text Files (*.txt);;C++ Files (*.cpp *.h)")); if (!fileName.isEmpty()) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Error"), tr("Could not open file")); return; } QTextStream in(&file); ui->textEdit->setText(in.readAll()); file.close(); }
}
void notepad::on_actionSave_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QString(),tr("Text Files (.txt);;C++ Files (.cpp *.h)"));if (!fileName.isEmpty()) { QFile file(fileName); if (!file.open(QIODevice::WriteOnly)) { // error message } else { QTextStream stream(&file); stream << ui->textEdit->toPlainText(); stream.flush(); file.close(); } }
}
@
-
notepad.ui
@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>notepad</class>
<widget class="QMainWindow" name="notepad">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>746</width>
<height>378</height>
</rect>
</property>
<property name="windowTitle">
<string>notepad</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>49</x>
<y>31</y>
<width>581</width>
<height>251</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
<item>
<widget class="QPushButton" name="quitbutton">
<property name="text">
<string>Quit</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>746</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen_2"/>
<addaction name="actionSave"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionOpen_2">
<property name="text">
<string>Open</string>
</property>
</action>
<action name="actionSave">
<property name="text">
<string>Save</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
@
@
#-------------------------------------------------Project created by QtCreator 2013-06-29T17:27:11
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = notepad
TEMPLATE = appSOURCES += main.cpp
notepad.cppHEADERS += notepad.h
FORMS += notepad.ui
@- notepad.h
@
#ifndef NOTEPAD_H
#define NOTEPAD_H#include <QMainWindow>
namespace Ui {
class notepad;
}class notepad : public QMainWindow
{
Q_OBJECTpublic:
explicit notepad(QWidget *parent = 0);
~notepad();private slots:
void on_quitbutton_clicked(); void on_actionOpen_2_triggered(); void on_actionSave_triggered();
private:
Ui::notepad *ui;
};#endif // NOTEPAD_H@