Facing problem in creating new cpp and header file?
-
void labtext() //Label text function
{
if(cursor.block().text().contains("",Qt::CaseInsensitive))
{
ui->label->setText("");}
if(cursor.block().text().contains("printf",Qt::CaseInsensitive)&& cursor.block().text().contains("(",Qt::CaseInsensitive)||cursor.block().text().contains("cout",Qt::CaseInsensitive)&&cursor.block().text().contains("<<",Qt::CaseInsensitive))
{
ui->label->setText("Printing to Standard Output");
}else if(cursor.block().text().contains("while",Qt::CaseInsensitive)&& cursor.block().text().contains("(",Qt::CaseInsensitive))
{
ui->label->setText("Checking condition for While Statement");
//QMessageBox::critical(this,"oo","fdgffh");
}else if(cursor.block().text().contains("switch",Qt::CaseInsensitive)&&cursor.block().text().contains("(",Qt::CaseInsensitive))
{
ui->label->setText("Checking condition for Switch Statement");
}
else if(cursor.block().text().contains("if",Qt::CaseInsensitive)&&cursor.block().text().contains("(",Qt::CaseInsensitive)&&(!cursor.block().text().contains(";",Qt::CaseInsensitive)))
{
ui->label->setText("Checking condition for If Statement");
}
else if(cursor.block().text().contains("else",Qt::CaseInsensitive)&& cursor.block().text().contains("if",Qt::CaseInsensitive))
{
ui->label->setText("Checking condition for If Statement");}
else if(cursor.block().text().contains("else",Qt::CaseInsensitive))
{
ui->label->setText("Checking condition for Else Statement");}
else if(cursor.block().text().contains("for",Qt::CaseInsensitive)&&cursor.block().text().contains("(",Qt::CaseInsensitive)) { ui->label->setText("For Loop - Initialization, Condition, Variable Update"); }
}
I want to create separate cpp and header file for this labtext function. Can anyone help me?
I have created header file :#ifndef LABELTEXT_H
#define LABELTEXT_H
#include <QLabel>class QLabel;
class Labeltext : public QLabel
{
Q_OBJECTpublic:
Labeltext(QLabel *parent = 0);protected:
void labtext();private:
};
#endif // LABELTEXT_H
But i dont known what to add in constructor of labeltext in cpp file.
-
You don't have to pass anything to the constructor.
Pass to the labtext() function a QString that contains the string you want to check, and return the string you want to display.
And make labtext() public.
Or: Send to labtext() a QString and a QString* and set the desired text to be displayed to the QString*.
Also, your function is a bit of a mess, and it's missing a few parentheses.