This is the eight session of the Expert System course using C++ and Qt. Now we’re gonna implement our PROPLexAnalyzer class using Qt containers and functions.

There’s a function that is a little complex to this video ( getToken()) that we’re gonna discuss in the following video.

So let’s start!


The constructor and destructor are quite simple, just setting values and delete them (automatically):



The next function is  buildToken() that is gonna create a LEXEM type variable and returning. This is useful for debugging purposes:

//If we want to create a Token manually
QPROPLexAnalizer::LEXEM QPROPLexAnalizer::buildToken(LEXEM::Type type, QString token){
    QPROPLexAnalizer::LEXEM L;
    return L;

Next one, the pushFile() function that checks if a file was opened correctly and push it to the file stack, otherwise displays a debugging error:

//Get file with rules and added to our stack of files
bool QPROPLexAnalizer::pushFile(QString fileName){
    QFile* file= new QFile(fileName);
    if(file->open(QFile::ReadOnly | QFile::Text)){
        return true;
	//Stream for debugging
    qDebug()<<"Error while uploading the file";
    return false;

popFile() function reverses the actions of the pushFile() function, deleting the first file in the stack:

//Eliminate the last file from the stack
void QPROPLexAnalizer::popFile(){
    delete file;

Lastly, read() function checks if there’s a file and save it all to a QString:

//Read through the stream and set it to the end,
//then we need to charge the file again.
QString QPROPLexAnalizer::read(){
        QTextStream stream(;
        return stream.readAll();
    return QString("empty");

You should also see our video where we developed these function step by step:


Thank you for seeing this video, remember to share the video, visit our web page and social media, and leave a comment if you have someone.


Leave a Reply

Your email address will not be published.