May 14, 2012

jaydeep17 jaydeep17
Lab Rat
11 posts

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 :)

9 replies

May 14, 2012

1+1=2 1+1=2
Hobby Entomologist
309 posts

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.

jaydeep17 wrote:

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 :( )…

May 14, 2012

Keozon Keozon
Lab Rat
21 posts

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.

  1. #include <QRegExp>
  2. #include <QValidator>

Then, in your QMainWindow constructor, for instance, you would need to set the regex up.

  1. QRegExp regex("REGEX GOES HERE");
  2. QValidator *nameofvalidator = new QRegExpValidator(regex,this);
  3. 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.

 Signature 

I know exactly where my computer is, so I have no idea how fast it’s going.

May 14, 2012

jaydeep17 jaydeep17
Lab Rat
11 posts

@1+1=2
I’m absolutely new to contribution.
So please bear with me..

here [qt.gitorious.org] 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 ??

May 14, 2012

jaydeep17 jaydeep17
Lab Rat
11 posts

@Keozon
I know this stuff…
what I don’t understand is the source of QEditLine.

May 14, 2012

Eddy Eddy
Area 51 Engineer
1296 posts

Have a look at this wiki [qt-project.org]

 Signature 

Qt Certified Specialist
Qt Ambassador

May 14, 2012

Tobias Hunger Tobias Hunger
Mad Scientist
3155 posts

Qt wants to be binary compatible. To help with that it uses the PIMPL Idiom [c2.com] 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.

May 14, 2012

jaydeep17 jaydeep17
Lab Rat
11 posts

@Eddy,
Thanks man !!
You really understood where I was stuck :)

May 14, 2012

jaydeep17 jaydeep17
Lab Rat
11 posts

@Tobias Hunger,
Thanks for the details, I’ll go through it..

by the way, is there any beginners post , to learn all this stuff ??

May 15, 2012

ChrisW67 ChrisW67
Robot Herder
385 posts

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.

 
  ‹‹ Strange File Buffer Behavior, Windows 7      Meaning of (QWidget *parent = 0) in constructor MyClass(QWidget *parent = 0); ››

You must log in to post a reply. Not a member yet? Register here!