Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. unresolved external symbol "class std::basic _string...
Forum Update on Monday, May 27th 2025

unresolved external symbol "class std::basic _string...

Scheduled Pinned Locked Moved Solved Installation and Deployment
9 Posts 4 Posters 975 Views
  • 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.
  • Z Offline
    Z Offline
    Zeyad Khaled
    wrote on last edited by
    #1

    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
    

    problem.png

    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

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Z 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        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.

        Z Offline
        Z Offline
        Zeyad Khaled
        wrote on last edited by
        #3

        @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);
        
        }
        
        jsulmJ 1 Reply Last reply
        0
        • Z Zeyad Khaled

          @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);
          
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @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()?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Z 1 Reply Last reply
          0
          • jsulmJ jsulm

            @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()?

            Z Offline
            Z Offline
            Zeyad Khaled
            wrote on last edited by
            #5

            @jsulm i did as u said and still gives me the same error problem 2.png

            jsulmJ 1 Reply Last reply
            0
            • Z Zeyad Khaled

              @jsulm i did as u said and still gives me the same error problem 2.png

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Zeyad-Khaled Then please use debugger to see where exactly it crashes and how the stack trace looks like.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Z 1 Reply Last reply
              1
              • jsulmJ jsulm

                @Zeyad-Khaled Then please use debugger to see where exactly it crashes and how the stack trace looks like.

                Z Offline
                Z Offline
                Zeyad Khaled
                wrote on last edited by
                #7

                @jsulm i tried as iam new to Qt but this is what i got , if u want something else please tell me how to get itproblem3.png
                , iam using plaintext edit in gui , shall i use Text edit or tect browser and may it be the reason for the problem ?

                J.HilkJ 1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Now go up to frame number three which is in your Check_XML_Consistency function, take a look what's wrong and fix it.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  2
                  • Z Zeyad Khaled

                    @jsulm i tried as iam new to Qt but this is what i got , if u want something else please tell me how to get itproblem3.png
                    , iam using plaintext edit in gui , shall i use Text edit or tect browser and may it be the reason for the problem ?

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @Zeyad-Khaled

                    when you do, what @Christian-Ehrlicher said, you will find the following
                    6740c508-5fa6-4dd9-893d-4c14cd41b2df-image.png
                    seems like your xml_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


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    2

                    • Login

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