Friday 15 June 2012

c++ - What is the easiest way to create a inherited class in Qt 5? -


I am a QT novice and whatever I am trying to do is create a custom QLineEdit with some customization (default) Square is alignment and default text). Right now I'm just trying to establish a base class, only inherited QWidget. This is what I have (very bad code I know):

Usertext (UTT. H):

  #ifndef UTXT_H #define UTXT_H #include & lt ; QWidget & gt; # Include & lt; QLineEdit & gt; Class Records: Public QWidget {Q_OBJECT Public: Clear Utext (QWidget * parent = 0); Caststring Text () Const .; Const QString displayText; Qt :: Alignment Alignment; Zero set diagrams (QT :: alignment); Hint: public slot:}; #endif // UTXT_H   

utxt.cpp:

  #include "utxt.h" utxt :: utxt (QWidget * origin): QWidget (parent ) {QString utxt :: text () {This-> Display text; } Zero utxt :: setAlignment (align Qt :: alignment) {this-> align = align; }}   

I know that this is actually wrong, and I keep errors in utxt.cpp on two functions "Local function definition is invalid". Can someone please point me in the right direction? I'm just trying to create a custom quid for promoting my second line editing thanks in advance !! Any help is appreciated!

QLineEdit can already be set and even more.

LE: As I said there is no need to do QLineEdit (or QWidget) for this functionality, but if you really want to do this, then you can only create your class And you can prepare a constructor, take the parameters you want, and QLineEdit with that methodology, something like this: // in header // ... I included guard and header class Skip the example of: Public QLin EEdit {Q_OBJECT public: // You can provide the default value of all the criteria or hard code to the Constructor's Definition Dictionary (Konststaststring and Default Text = "Test Text", Qt :: Alignment Alignment = QT :: Alenjraite, QuDudeGate * Parent = 0) in calls made from; }; In the // cpp utxt :: utxt (const QString and defaultText, Qt :: alignment alignment, QWidget * root): QLineEdit (parent) {// call set placeholder parameter or default set placeholder text with hard-code (defaultText) ; // Alignment Alignment Alignment Alignment Only; }

No comments:

Post a Comment