Yeah actually i had created this labtxt function in mainwindow but now i want to create separate cpp and header file only for this particular function labtext. So i have created header file for labtxt but i dont know what to add in constuctor of labeltext in its cpp file.
I don't see any need to do something in the constructor of class Labeltext, just pass the parent argument to the base class constructor.
Cheers,
_
ok...then labeltext.h header file will include:
#ifndef LABELTEXT_H
#define LABELTEXT_H
#include <QLabel>
#include<mainwindow.h>
class QLabel;
class Labeltext : public QPlainTextEdit
{
Q_OBJECT
public:
Labeltext(QLabel *parent = 0);
protected:
void labtext();
private:
};
#endif // LABELTEXT_H
and labeltext.cpp will contain:
#include "labeltext.h"
#include<mainwindow.h>
#include<QLabel>
Labeltext::Labeltext(QLabel *parent) :QPlainTextEdit(parent)
{
}
void labtext()
{
if(cursor.block().text().contains("",Qt::CaseInsen sitive))
{
ui->label->setText("");
}
if(cursor.block().text().contains("printf",Qt::Cas eInsensitive)&& cursor.block().text().contains("(",Qt::CaseInsensi tive)||cursor.block().text().contains("cout",Qt::C aseInsensitive)&&cursor.block().text().contains("< <",Qt::CaseInsensitive))
{
ui->label->setText("Printing to Standard Output");
}
......//so on
}
then how to call in mainwindow.cpp?
Well you'll have to create an instance of Labeltext in your main window, and then call the function from that. You'll have to include the labeltext header in mainwindow.
I don't mean to be rude, but are you sure you know enough about c++ to be making what appears to be and IDE/debugger for it?
Label is contain in Frame in my GUI so parent of labeltext should QFrame only..
So Labeltext(QLabel *parent = 0); is replaced with Labeltext(QFrame *parent = 0);
and Class Labeltext should inherit properties from Class Label.
So class Labeltext : public QPlainTextEdit is with class Labeltext : public QLabel
Am i correct now?
Yes, that sounds a lot better
Cheers,
_
So labeltext.cpp contain only one function void labtext(). So how to call this function from mainwindow.cpp?
Qt Code:
#include "labeltext.h" #include<QFrame> #include<QLabel> { } void labtext() { 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"); } }To copy to clipboard, switch view to plain text mode
Last edited by anda_skoa; 4th February 2014 at 09:21. Reason: Added code tags
I am not sure I understand the question, a method call is basic C++
Qt Code:
pointerToLabelTextObject->labtext();To copy to clipboard, switch view to plain text mode
Cheers,
_
Its not working showing Error undefined reference to Labeltext::labtext();
I declared class object in mainwindow.h like
Labeltext *labeltext;
and i called labtext() with the help of class Labeltext object i.e labeltext in this way :
labeltext->labtext()
Last edited by parulkalra14; 4th February 2014 at 11:30.
That is a linker error, so make sure that the code for labtext() is actually compiled. I.e. make sure that the respective source file is listed in SOURCES in your .pro file.
Cheers,
_
If this is what your .cpp file really looks like:
Qt Code:
{ } void labtext() { ... }To copy to clipboard, switch view to plain text mode
then you have not implemented the function labtext() as a member of the class Labeltext. You have implemented it as a standalone function inside a cpp file. Your linker is complaining that it can't find Labeltext::labtext() because in fact you declared it in the header, but didn't implement it.
I think you need to learn how to walk in C++ before you attempt to write code in C++ + Qt.
Bookmarks