Help needed : Want to contribute to Qt
-
I want to add a feature to QLineEdit widget, to make input validation more ease to use..
but I'm finding it difficult to figure out, how the source works.I want to read the implementation of the setValidator(QRegExValidator) method, but I'm not getting it.
I saw the source, but it passes to some d->control..(which I don't get :( )...please someone help...
Thanks :)
-
If you want to contribute code to Qt, follow http://qt-project.org/wiki/Setting-up-Gerrit
But I still doesn't understand what's the problem you come with now.
[quote author="jaydeep17" date="1337025851"]
I want to read the implementation of the setValidator(QRegExValidator) method, but I'm not getting it.
I saw the source, but it passes to some d->control..(which I don't get :( )...
[/quote] -
I'm assuming you want to disallow special characters, etc in your QLineEdit widget.
This is fairly simple to do. The most difficult part is understanding regular expressions. If you don't understand them, a Google search will turn up tons of tutorials.
First, you'll need to includes, if you don't already have them.
@#include <QRegExp>
#include <QValidator>@Then, in your QMainWindow constructor, for instance, you would need to set the regex up.
@QRegExp regex("REGEX GOES HERE");
QValidator *nameofvalidator = new QRegExpValidator(regex,this);
ui->QLineEditName->setValidator(nameofvalidator);
@And that's it. Keep in mind that nameofvalidator is in the heap.
The first line sets up your regular expression object. As an example of a regex, "([A-Z]|[a-z])*" allows any number of alpha characters, no numbers, no specials, etc.
The next line initializes a QValidator object on the heap with the validation settings from regex.
And the last line assigns the validation object to the actual QLineEdit widget. -
@1+1=2
I'm absolutely new to contribution.
So please bear with me.."here":http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/widgets/qlineedit.cpp is the source of QLineEdit
go to line no. 573, that method returns a QValidator, I understand that,
but what does line no. 576 mean ?what is 'd' & 'control' ??
where is it defined ?? -
@Keozon
I know this stuff...
what I don't understand is the source of QEditLine. -
Have a look at "this wiki":http://qt-project.org/wiki/Dpointer
-
Qt wants to be binary compatible. To help with that it uses the "PIMPL Idiom":http://c2.com/cgi/wiki?PimplIdiom a lot to hide implementation details.
Qt's way is a bit more involved than the one described in the article: Only the base class holds a pointer, the derived classes have a derived private class. The Q_D macro is used to access that, providing a variable called 'd' to access the private data. The class behind the d-pointer is usually called WhateverPrivate and tends to be defined in a header ending with _p.h.
I hope this helps.
-
@Eddy,
Thanks man !!
You really understood where I was stuck :) -
@Tobias Hunger,
Thanks for the details, I'll go through it..by the way, is there any beginners post , to learn all this stuff ??
-
Have a look at the file qglobal.h in the Qt sources for Q_DECLARE_PRIVATE and Q_D macros then revisits the QLineEdit sources.
A beginners guide to hacking Qt? Not that I am aware of. Hacking Qt library sources in anything but the most trivial way is not a beginner's domain. You start with Qt Assistant, the code, online resources, and good deal of inquisitiveness when faced with some thing you don't immediately follow. You will need to walk before you can run. Chances are that in the process of learning you will discover you don't need to modify the Qt sources anyway.