Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT 5.0 Project issue
Forum Updated to NodeBB v4.3 + New Features

QT 5.0 Project issue

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sonu_pal
    wrote on last edited by
    #1

    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 :

    1. C:\Users\acer\Documents\Qt5.0\notepad\main.cpp:6:

    bq. error: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'bq.

    1. 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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bagipro
      wrote on last edited by
      #2

      Probably u dont include some library or wrong wrote .pro file.
      Post the code

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sonu_pal
        wrote on last edited by
        #3

        These are the below codes :

        1. main.cpp

        @ #include "notepad.h"
        #include <QApplication>

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        notepad w;
        w.show();

        return a.exec&#40;&#41;;
        

        }@

        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&#40;fileName&#41;;
                   if (!file.open(QIODevice::ReadOnly&#41;) {
                       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&#40;fileName&#41;;
                        if (!file.open(QIODevice::WriteOnly&#41;) {
                            // error message
                        } else {
                            QTextStream stream(&file);
                            stream << ui->textEdit->toPlainText();
                            stream.flush();
                            file.close();
                        }
                    }
        

        }

        @

        1. 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>
          @

        2. notepad.pro

        @
        #-------------------------------------------------

        Project created by QtCreator 2013-06-29T17:27:11

        #-------------------------------------------------

        QT += core gui

        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

        TARGET = notepad
        TEMPLATE = app

        SOURCES += main.cpp
        notepad.cpp

        HEADERS += notepad.h

        FORMS += notepad.ui
        @

        1. notepad.h

        @
        #ifndef NOTEPAD_H
        #define NOTEPAD_H

        #include <QMainWindow>

        namespace Ui {
        class notepad;
        }

        class notepad : public QMainWindow
        {
        Q_OBJECT

        public:
        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@

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bagipro
          wrote on last edited by
          #4
          1. U should to add external libs to .h file
          2. On my pc that code was compiled successfully. Did you try to run qmake?
          1 Reply Last reply
          0
          • S Offline
            S Offline
            sonu_pal
            wrote on last edited by
            #5

            Hi,

            The issue ss resolved. MINGW compiler was not configured in kits.

            I reinstalled the QT 5.0.2 setup and issue got fixed.

            Thanks

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved