[Qt-interest] 答复: capture screen
Carsten Breuer
CarstenBreuerQt at textwork.de
Tue Jun 15 21:48:05 CEST 2010
Hi Alex,
> There is nothing wrong with using "this" even though it is not required.
> Sometimes it saves you time clearly stating that you are calling the member function and not global one.
I disagree here. The "this" desease started with scripting languages like
python, java etc. C++ works over a decade without it because developers
understand namespaces.It make the code less readable, worse maintainable
and is pretty much useless. Torvalds would say "stupid and uggly" ;-).
There are cases, where the use of "this" clarify things, i agree.
To use this for every access of class members is IMO pretty worse
and in the context of the given example it was totally useless, more
than then that, redundant:
>hide();
>this->hide();
> My own opinion is that using "this" does improve clarity and if you don't tend to combine complicated operations in long lines
> have only positive effect on readability and may even improve speed the code is written.
Well, the compiler removes "this" anyway.
In my opinion a method of a class should make it pretty clear what happen.
That's one of the reason we love QT. If a global method exist with the
same name, then the code often have a structure problem.
Of course, you have to understand namespaces.
> For example VC will provide you a list of available class members and choosing between them may not only save you time on typing,
> but also may save you time for additional compilation required if you mistype the member name.
VC do this also for class members without this, also QtCreator.
> But during your life as a programmer you will be forced to follow different styles,
Exact. I was in the last 15 years more then once member of a team that had
to develop such coding guidelines. A team need such a understanding of the
code they develop. This is vital and pure lessons learned.
In security environments we also have to follow guidelines like MISRA
and Scott Meyers recommendations are always worth to look at.
Nonetheless, the usage of "this" is not in that scope ;-).
Regards,
Carsten
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Malyushytsky, Alex
> Sent: Monday, June 14, 2010 3:03 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] 答复: capture screen
>
> I don't think hide does anything beside scheduling an event, which may be not even processed
> When you are trying to capture.
>
> I would either try to call
> QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents )
>
> after hide() or made capture_screen() a slot if it is not, moved show() there and used
>
> QTimer::singleShot(0, this, SLOT(_ ()));
>
> to invoke capture. In this case you will have to move show() at the end of capture_screen()
>
> Hope this helps,
> Alex
>
>
>
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of pengliang(??)
> Sent: Sunday, June 13, 2010 6:51 PM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] 答复: capture screen
>
> Hi Luis:
> Thank you.
> Hi Carsten:
> Thanks for your advice.
>
> I have modified them, but the problem still does exist.
> -----------------------------------
> if(setHideWnd == true) {
> hide();
> capture_screen();
> show();
> } else {
> Capture_screen();
> }
> ----------------------------------
> void MainWindow::capture_screen()
> {
> QString picture_file= QString("%1/%2").arg(save_dir).arg("picture ");
> QPixmap fullscreenmap;
> fullscreenmap =QPixmap::grabWindow(QApplication::desktop()->winId());
> fullscreenmap.save(picture_file,"JPG",-1);
> }
> -------------------------------------------
> Whether I still made some mistakes?
>
>
>
> -----邮件原件-----
> 发件人: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] 代表 Luis Lezcano Airaldi
> 发送时间: 2010年6月13日 0:16
> 收件人: qt-interest at trolltech.com
> 主题: Re: [Qt-interest] capture screen
>
> El 12/06/10 07:31, Carsten Breuer escribió:
>> Hi pengliang,
>> hi all,
>>
>>
>>> Please see the snippet bellow. (I want to minimizied the windows
>>> and capture the screen, but application capture screen before the window
>>> was fully minimized.) why? Can anybody tell me why? Or give me some ideas.
>>>
>> The code needs a lot of cleanup because if is unnecessary complicated.
>> The function windowHideShow is almost useless.
>>
>> You have created some really funny things here:
>>
>> this-hide(); LOL
>>
>> You take the address of the widget and subtract the result of
>> hide of it and throw the result away. Funny.
>>
>> I think you meant this->hide();
>> You do the same here: while(this-isHidden())
>>
>> NEVER EVER use this inside a class without the need of
>> doing so! The only reason to use this is to give another
>> class a pointer to your instance.
>> The use of this is a disease that occur since python programmers
>> try to use C++ (in python you have to do it that way with self).
>>
>> Here some other points:
>>
>> 1. Why do you want to toggle isHideWnd. No need for that.
>> You have two variables doing the same thing
>> 2. You try to call functions twice! One time with this, the
>> other time correct.
>>
>> Clean up the code first and REMOVE all the useless "this".
>>
>>
>> Best Regards,
>>
>
> That's the problem when they use html in a mailing list. Your client
> removed the ">" of this->hide() so you're not seeing it.
>
> Back to the problem, what happens if you uncomment the line
> qApp->proccessEvents()? I'm not sure, but that should minimize the
> window and then you take the screenshot...
>
> Regards.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> ---------------------------------------------------------------------------------------------------
> Weidlinger Associates, Inc. made the following annotations.
>
> “This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
>
> “Please consider our environment before printing this email.”
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list