简体   繁体   中英

Qt5 Unidentified reference to QInputDialog and QMessageBox.. ERROR

I am busy with my university assignment, i'm new to Qt, C++ and i am required to: Define and implement the Address class in separate header and source files

I am getting confused with Qt4 and Qt5 as the prescribed text book gives all examples in Qt4 yet we are required to code with Qt5. I keep getting errors and the latest error is :

 error: undefined reference to 
 Dialog7getTextEP7QWidgetRK7QStringS4_N9QLineEdit8EchoModeES4_
 Pb6QFlagsIN2Qt10WindowTypeEES8_INS9_15InputMethodHintEE'
 error: undefined reference to 
 MessageBox11informationEP7QWidgetRK7QStringS4_6QFlagsINS_
 14StandardButtonEES6
 collect2.exe:-1: error: error: ld returned 1 exit status

I am very confused and stuck, please if anyone can steer me in the right direction i would greatly appreciate it, This is my code so far:

Header File:

#ifndef ADDRESS_H_
#define ADDRESS_H_
#include <QString>
#include <QFile>
#include <QStringList>
#include <QtCore>
QTextStream cout(stdout);
QTextStream cerr(stderr);

class Address{
public:
Address();
void setLines(QString ad, QString sep);
QString getPostalCode() const;
QString toString(QString sep) const;
static bool isPostalCode(QString pc);
private:
static QStringList lines;
};

#endif // ADDRESS_H_

Main File:

#include "address.h"
#include <iostream>
#include <QFile>
#include <sstream>
#include <fstream>
#include <QStringList>
#include <QString>
#include <QTextStream>
#include <QCoreApplication>
#include <QtWidgets/QInputDialog>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QLineEdit>

Address::Address(){}

void Address::setLines(QString ad, QString sep){
QStringList lines;
lines = ad.split(sep, QString::SkipEmptyParts);
}

QString Address::getPostalCode() const{
QStringList lines;
return lines.last();
}

QString Address::toString(QString sep) const{
QStringList lines;
return lines.join(sep);
}

bool Address::isPostalCode(QString pc){
if (pc >= "0" && pc <= "9999")
    return true;
else
    return false;

}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    while(true)
{
    QString userInput = QInputDialog::getText(0,"Address Input","Please 
    enter your address:");
    QLineEdit::EchoMode ok = QLineEdit::Normal;
    QString();
    if(ok && !userInput.isEmpty())
{
    Address ad;

    QMessageBox::information(0, "User Address",ad.toString(userInput));
}
}
return 0;
}

I got the same error. Basically, there's an issue with your compiler MingW and qMake. The best suggestion I have is to uninstall QTcreator and everything that references it. And re-install it using the new version: https://www.qt.io/download This will install everything you need and all the right directories. Hope this helps.

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