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.
ok i understand where i am going wrong...i replaced below code:
Labeltext::Labeltext(QFrame *parent) :QLabel(parent)
{
}
void labtext()
{
...
}
with
Labeltext::Labeltext(QFrame *parent) :QLabel(parent)
{
}
void Labeltext:: labtext()
{
QTextCursor cursor=QPlainTextEdit.textCursor();
if(cursor.block().text().contains("",Qt::CaseInsen sitive))
{
Qlabel->setText("");
}
}
Something is wrong with this highlighted line and i am not able to find and my appication is stopped working when i run it. Need help!!!
Last edited by parulkalra14; 5th February 2014 at 07:36.
What do you expect this line to do?
Do you have a member variable called QPlainTextEdit? Is its type a class that has a textCursor() method?
Cheers,
_
I am declaring cursor variable and want to link cursor with plainTextEdit so that whenever cursor moves on a text, the label associated with that particular text will displayed on a Label Widget.
This thread is killing me. You really need to take a class or read a book on C++.
"QPlainTextEdit.textCursor()" is calling the function textCursor on an object named QPlainTextEdit.
What you want is to call the function textCursor on an object of type QPlainTextEdit.
So you should have a QPlainTextEdit declared somewhere
and then call textCursor on thatQt Code:
QPlainTextEdit myPlainTextEdit;To copy to clipboard, switch view to plain text mode
Qt Code:
myPlainTextEdit.textCursor();To copy to clipboard, switch view to plain text mode
Bookmarks