Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. Facing problem in creating new cpp and header file?

Facing problem in creating new cpp and header file?

Scheduled Pinned Locked Moved India
3 Posts 3 Posters 1.9k 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.
  • P Offline
    P Offline
    parulkalra14
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ovidiub13
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • IamSumitI Offline
        IamSumitI Offline
        IamSumit
        wrote on last edited by
        #3

        Hii parulkalra14,

        So you don't know How to add .cpp and .h file in your project.
        You need to look some Qt docs or videos. That will give you some idea.

        Be Cute

        1 Reply Last reply
        0

        • Login

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