7/28/2017

I wanna give you a gift - a series of gifts


“I wanna give you a gift - a series of gifts, leading up to... well, I wanna call it "the ultimate gift;" but, you fail in any way, it's over.”
Dear friends, How would you feel if you had a billionaire grandpa or billionaire dad? Especially, how would you feel if he was going to give you whole bunch of money after his death? What would happen if he already deceased after made you as his successor? You may feel sad but that sadness comes with a fortune. You would be a billionaire.
When Red Stevens dies members of his family feel more or less like you. Even though It doesn't reflect any sadness about Red, everybody are curious about what Mr. Stevens kept for them through his last will. Jason Stevens, beloved grandson of Red, comes to funeral with his girlfriends. No sad at all. He lived all his life with a trust fund and never did a job and want to continue his lifestyle forever.
After the solemn funeral of Red, his wealthy family get together around the office table of old Mr. Hamilton, the family lawyer. Dissatisfaction goes around everywhere. Everyone leave with dissatisfaction about what they have gotten. Except Jason who still doesn’t know what he will have. He sits there without sense.


Spoiler alert: If you want to see the movie with curiosity just go and watch before reading beyond this.
Finally, it’s Jason’s time. Jason and Hamilton appear in a room without anyone but themselves. There is a magic box appears middle of the table. Then deceased Red speaks “I wanna give you a gift - a series of gifts, leading up to... well, I wanna call it "the ultimate gift;" but, you fail in any way, it's over.” It’s recorded speech of Red before his death. Now Jason starts his journey to find his gift, literally series of gifts.

Dear friends, I detailed you beginning of one of my favorite movies, The Ultimate Gift. It was directed by Michael O. Sajbel based on Jim Stovall’s novel 'The Ultimate Gift'. Such a nice movie I have ever seen. It shows us the value of experienced life rather than billion dollars. As I mentioned before, plot goes around rich grandfather who doesn’t like to give his money to hands with unlifted fingers or to a person who doesn’t know value of money, amount of tears and sweats spent to earn. Throughout the plot grandfather empowers his grandson to be experienced enough to bear billions of  dollars.
These experiences shows as series of gifts, series of twelve gifts which lead to ultimate gift. The gift of work, the gift of money, the gift of friends, the gift of learning, the gift of problems, the gift of family, the gift of laughter, the gift of dreams, the gift of giving, the gift of gratitude, the gift of a day, the gift of love all are gifts he received.
He, Jason, flied to rural Texas to collect something he don’t know. Lazy boy who not lift a finger had to woke up early in the morning to work hard in a field of Texas. He had to work under hot sun. After some time he came back with nothing, but with the gift of work.
He found one true friend. He survived from zero money condition. He helped to others. He learned to help others. Finally, he got his fortune with a bunch of life values.
My dear friends, did he acquire billions of dollars only, didn’t he? No. He acquired billions of dollars with a new life. A better life. That’s the ultimate gift.

10/10/2014

Solution for fillData->clip->clipRect.isEmpty() in Qt

After long time I'm going to write another blog post.  This is regarding the Qt and it will detail a solution for the problem of fillData->clip->clipRect.isEmpty(). I got this problem as below cage while trying to create a 'title block' for the engineering drawing. 

Sample title block (copy rights)
I created a QPrintPreviewDialog which previews engineering drawings generated by the application. I draw rectangle to represent title block which consists details of the drawing. At some points length of the detail higher than the space of the rectangle. Then I got below run-time error.


ASSERT: "!fillData->clip->clipRect.isEmpty()" in file painting/qpaintengine_raster.cpp, line 4435

The simple answer is you are going to write the text in the rectangle which is not have enough space to show your content.

You can do following things.
1. Increase the size of Rectangle.
2. Decrease the font size.
3. Or use Qt.TextElideMode

enum Qt::TextElideMode

This enum specifies where the ellipsis should appear when displaying texts that don't fit:

ConstantValueDescription
Qt::ElideLeft0The ellipsis should appear at the beginning of the text.
Qt::ElideRight1The ellipsis should appear at the end of the text.
Qt::ElideMiddle2The ellipsis should appear in the middle of the text.
Qt::ElideNone3Ellipsis should NOT appear in the text.




5/06/2014

ASSERT: "uint(i) < uint(size())" in file bla.. bla.., line bla.. in Qt

Hope you know these days I'm trying Qt\C++. Today I spent lot of my valuable time for solve the error mentioned in the title (ASSERT: "uint(i) < uint(size())" in file bla.. bla.., line bla..). It is run time error and I tried lot to find what was happening. At that time I have no knowledge about the 'Q_ASSERT' also.

A one bug hidden inside below code. Can you find it?


for (int row = 0; row < heights().count(); ++row)
        {
            for (int col = 0; col < ampererates().count(); ++col)
            {
                QModelIndex index = item_model->index(row,col,QModelIndex());
                no_of_components = item_model->data(index).toString();

                if(no_of_components.toInt()>0)
                {
                    height = heights().at(row);
                    ampererates = ampererates.at(col);
                    item_details.clear();
                    item_details.append(QString::number(selected_width));
                    item_details.append(height);
                    item_details.append(amperate);
                    item_details.append(no_of_components);

                    selected_components.append(item_details);
                }
            }
        }

I know it is very difficult to found a bug without the whole story. But I'm writing this post to anyone who got the same problem as a beginner like me and detail about my thinking pattern.

As a first step I put qDebug() s intermediate of the lines. And I found the bug in below line.
ampererates = ampererates.at(col); 

Then I thought what type of error it was. It mentioned something about sizes. Sizes?? something about arrays or List..?? Then I thought if there is no error in count() of the same list. Why it was informing error like out of bound?
for (int col = 0; col < ampererates().count(); ++col) Working fine.
ampererates = ampererates.at(col); ++col) Not working

Variable ampererates is QString. And ampererates() is QStringList. Ohh.. Shit.. I missed the brackets. Solution founded. I was trying to read a char from QString instead of read string from QStringList. There is no guarantee that index position is valid.

Then I checked what .at() doing in different classes. As mentioned in there class references.

const QChar QString::at ( int position ) const

Returns the character at the given index position in the string.
The position must be a valid index position in the string (i.e., 0 <= position < size()).

const T & QList::at ( int i ) const

Returns the item at index position i in the list. i must be a valid index position in the list (i.e., 0 <= i < size()).
This function is very fast (constant time).

QStringList inhereted from QList.

OK. Thinks this is help somebody to solve same issue. I'm going to learn further what 'Q_ASSERT' do.

Thanks for reading. Have a nice day.