unresolved external symbol "class std::basic _string...
-
The project was running well yesterday , i did't change anythink and now it's not working , although the function i want didn't word yesterday but the program get's built and opened , iam a beginner to qt and using it for a college project so i need help , i searched alot and tried most of solns on internet but nothing worked
here is my code:
Project1.pro:QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 0 CONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ Consistency.cpp \ main.cpp \ mainwindow.cpp HEADERS += \ Consistency.h \ mainwindow.h FORMS += \ mainwindow.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target RESOURCES += \ Res.qrc RC_ICONS =application_icon.ico
main.cpp:
#include "mainwindow.h" #include <QApplication> #include "Consistency.h" using namespace std; int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
mainwindow.cpp:
#include "mainwindow.h" #include "Consistency.h" #include "ui_mainwindow.h" #include<string> #include<iostream> using namespace std; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_actionAbout_triggered() { QMessageBox::about(this,"About the Project","An XML editor (Windows Application) to facilitate the editing of xml files. User can load XML file and choose multiple features from buttons in GUI. Once a file is uploaded, the program detects the errors, corrects them, show an error message with number of errors in input file, creates a new consistent file in the same path as the input file ,and views a successful message indicating that the process was successful. Also, user can format XML file, minify it, convert it into JSON file, compress it to reduce its size ,and able to decompress it."); } void MainWindow::on_actionAbout_us_triggered() { QMessageBox::about(this,"About the Project","Abous Us"); } void MainWindow::on_actionCopy_triggered() { ui->plainTextEdit->copy(); } void MainWindow::on_actionPaste_triggered() { ui->plainTextEdit->paste(); } void MainWindow::on_actionUndo_triggered() { ui->plainTextEdit->undo(); } void MainWindow::on_actionRedo_triggered() { ui->plainTextEdit->redo(); } void MainWindow::on_pushButton_2_clicked() { QString file_name=QFileDialog::getOpenFileName(this,"Select a file","C://"); QFile file(file_name); if(!file.open(QFile::ReadOnly |QFile::Text)){QMessageBox::warning(this,"Warning!","file is not opening");} QTextStream in(&file); QString text=in.readAll(); ui->plainTextEdit->setPlainText(text); } void MainWindow::on_pushButton_3_clicked() { QString file_name=QFileDialog::getSaveFileName(this,"Select a file","C://",tr("All files (*.*);;XML files (*.xml);;Text files (*.txt);;JSON Files(*.json)")); QFile file(file_name); if(!file.open(QFile::WriteOnly |QFile::Text)){QMessageBox::warning(this,"Warning!","file is not Saved");} QTextStream out(&file); QString text=ui->plainTextEdit->toPlainText(); out<<text; file.flush(); file.close(); } void MainWindow::on_pushButton_4_clicked() { QString text =ui->plainTextEdit->toPlainText(); string x=text.toStdString(); string Result=Check_XML_Consistency(x); QString str = QString::fromStdString(Result); ui->plainTextEdit->setPlainText(str); }
Consistency.cpp:
#include "Consistency.h" #include<iostream> #include<string> #include<stack> #include<vector> using namespace std; string Check_XML_Consistency(string &xml_file) { string xml_edit = xml_file; int pre_index; int begin_index; int true_index; char temp; int flag = 0; int flag_check = 0; int diffrence = 0; stack <string>xml_check_close_outer; stack <string>xml_check_close_outer_temp; stack <string>xml_check_close_inner; string xml_check_close_string; string check_top; string correct; for (int i = 0; i < xml_edit.length(); i++) { if (xml_edit[i] == '<') { i++; if (xml_edit[i] != '/') { begin_index = i; pre_index = i - 1; while (xml_edit[i] != '>') i++; true_index = i; diffrence = true_index - begin_index; if (!xml_check_close_inner.empty()) { xml_edit.insert(pre_index, ">"); xml_edit.insert(pre_index, xml_check_close_inner.top()); xml_edit.insert(pre_index, "</"); correct = xml_check_close_inner.top(); xml_check_close_inner.pop(); begin_index = pre_index + (int)correct.size() + 4; true_index = begin_index + diffrence; i = true_index; } i++; while (xml_edit[i] != '<') { temp = xml_edit[i]; if (temp == ' ') { i++; continue; } else { flag = 1; break; } } i = true_index; if (flag == 1) { xml_check_close_inner.push(xml_edit.substr(begin_index, i - begin_index)); flag = 0; } else { xml_check_close_outer.push(xml_edit.substr(begin_index, i - begin_index)); } } else if (xml_edit[i] == '/') { i++; begin_index = i; pre_index = i - 2; while (xml_edit[i] != '>') i++; xml_check_close_string = xml_edit.substr(begin_index, i - begin_index); if (!xml_check_close_inner.empty()) { xml_edit.insert(pre_index, ">"); xml_edit.insert(pre_index, xml_check_close_inner.top()); xml_edit.insert(pre_index, "</"); correct = xml_check_close_inner.top(); xml_check_close_inner.pop(); begin_index = pre_index + (int)correct.size() + 5; i = begin_index + (int)xml_check_close_string.size(); xml_edit.erase(begin_index - 2, i - begin_index + 3); i = begin_index - 3; } else { if (xml_check_close_outer.top() == xml_check_close_string) { xml_check_close_outer.pop(); } else { xml_edit.insert(pre_index, ">"); xml_edit.insert(pre_index, xml_check_close_outer.top()); xml_edit.insert(pre_index, "</"); correct = xml_check_close_outer.top(); xml_check_close_outer.pop(); begin_index = pre_index + (int)correct.size() + 5; i = begin_index + (int)xml_check_close_string.size(); pre_index = begin_index - 2; while (!xml_check_close_outer.empty()) { if (xml_check_close_outer.top() != xml_check_close_string) { xml_check_close_outer_temp.push(xml_check_close_outer.top()); xml_check_close_outer.pop(); } else { while (!xml_check_close_outer_temp.empty()) { xml_check_close_outer.push(xml_check_close_outer_temp.top()); xml_check_close_outer_temp.pop(); } flag_check = 1; break; } } if (flag_check == 1) { while (xml_check_close_outer.top() != xml_check_close_string) { xml_edit.insert(pre_index, ">"); xml_edit.insert(pre_index, xml_check_close_outer.top()); xml_edit.insert(pre_index, "</"); correct = xml_check_close_outer.top(); xml_check_close_outer.pop(); begin_index = pre_index + (int)correct.size() + 5; i = begin_index + (int)xml_check_close_string.size(); pre_index = begin_index - 2; } xml_edit.insert(pre_index, ">"); xml_edit.insert(pre_index, xml_check_close_outer.top()); xml_edit.insert(pre_index, "</"); correct = xml_check_close_outer.top(); xml_check_close_outer.pop(); begin_index = pre_index + (int)correct.size() + 5; i = begin_index + (int)xml_check_close_string.size(); pre_index = begin_index - 2; flag_check = 0; } else { while (!xml_check_close_outer_temp.empty()) { xml_check_close_outer.push(xml_check_close_outer_temp.top()); xml_check_close_outer_temp.pop(); } xml_edit.erase(begin_index - 2, i - begin_index + 3); i = begin_index - 3; } } } } } } if (!xml_check_close_inner.empty()) { xml_edit.append("</"); xml_edit.append(xml_check_close_inner.top()); xml_edit.append(">"); xml_check_close_inner.pop(); } while (!xml_check_close_outer.empty()) { xml_edit.append("</"); xml_edit.append(xml_check_close_outer.top()); xml_edit.append(">"); xml_check_close_outer.pop(); } return xml_edit; }
mainwindow.h:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMessageBox> #include <QMainWindow> #include <QFileDialog> #include <QFile> #include <QTextStream> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: void on_actionAbout_triggered(); void on_actionAbout_us_triggered(); void on_actionCopy_triggered(); void on_actionPaste_triggered(); void on_actionUndo_triggered(); void on_actionRedo_triggered(); void on_pushButton_2_clicked(); void on_pushButton_3_clicked(); void on_pushButton_4_clicked(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
Consistency.h:
#ifndef CONSISTENCY_H #define CONSISTENCY_H #include<string> using namespace std; string Check_XML_Consistency(string xml_file); #endif // CONSISTENCY_H
i want help in this problem and in the function i want to be called when i press the CheckErrors button it should take string and return string i tested it in vs and it works well but i can't combine it with the gui
-
It for sure did not link before when you did not change something in-between.
string Check_XML_Consistency(string xml_file);
string Check_XML_Consistency(string &xml_file)
These are two different functions.
-
@Christian-Ehrlicher Well , i don't know how did that come in there , thx for help ,
iam trying to use QT for a project to check consistency of xml file , i have a function called Check XML Consistency(); ,it takes a string as data type and returns also a string , i have a problem when i try to use it with QT as when i cast the data in the text filed to string and cast it back to qtstring to show it , the program gives me an error , i checked and know that the problem is with spaces when i remove all spaces from my text editor the program runs well ,
void MainWindow::on_pushButton_4_clicked() { QString text =ui->plainTextEdit->toPlainText(); string x=text.toStdString.constData(); string Result=Check_XML_Consistency(x); QString str = QString::fromStdString(Result); ui->plainTextEdit->setPlainText(str); }
-
@Zeyad-Khaled said in unresolved external symbol "class std::basic _string...:
the program gives me an error
And what is this error?
Why don't you simply use QString::toStdString()? Why this constData()? -
@Zeyad-Khaled Then please use debugger to see where exactly it crashes and how the stack trace looks like.
-
Now go up to frame number three which is in your
Check_XML_Consistency
function, take a look what's wrong and fix it. -
when you do, what @Christian-Ehrlicher said, you will find the following
seems like yourxml_check_close_outer
std::stack is empty and you try to access the non existent top() element, what then crashes.At least, when your code, that you posted is a 1:1 copy and paste :D