星海's Blog

老头初学编程
Qt = Cute Great LoveIt 之Json TreeWidget的生成 与QHttpMultiPart

Qt源代码初探(一)——qglobal.h

星海 posted @ 2013年5月12日 17:43 in 通用知识 , 5446 阅读
/*
  Qt中qRound的实现,在负数的情况下不同于一般的四舍五入。
  如果负数尾数 <=.5的情况下,则舍弃尾数。(注意,=的情况下也舍弃o)
  如果负数尾数 > 0.5的情况下,则负小数整数部分-1
**/
Q_DECL_CONSTEXPR inline int qRound(double d)
{ return d >= 0.0 ? int(d + 0.5) : int(d - double(int(d-1)) + 0.5) + int(d-1); }

/**
 * Qt中通过模板获取qptrdiff的类型
 * TODO: 知识点:我能力有限,暂时不清楚模板应用底层原理。
 * 通过模板参数直接获取相关类型
 * 似乎与工厂设计模式有些相近(只是个人理解,如有误请留言指正)
 */

template <int> struct QIntegerForSize;
template <>    struct QIntegerForSize<1> { typedef quint8  Unsigned; typedef qint8  Signed; };
template <>    struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
template <>    struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
template <>    struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
typedef QIntegerForSizeof<void*>::Unsigned quintptr;
typedef QIntegerForSizeof<void*>::Signed qptrdiff;
typedef qptrdiff qintptr;

/* unused参数的非warnning */
#  define Q_UNUSED(x) (void)x;

/*
 * QGlobalStatic在非线程情况下为一般static实现
 * 在线程情况下使用了QAtomicPointer自动指针,然后用QGlobalStaticDeleter注册其智能指针,在QGlobalStaticDeleter析构后,自动delete掉QGlobalStatic对象。
 * TODO: 具体原因暂时不清
 */

/*
 * 因浮点数不适宜用 == 好直接比较,所以采用了浮点数精度模糊的方法
 */
Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(double p1, double p2)
{  return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));}

/**
 * Q_FOREACH宏末尾
 * 主要是兼顾Q_FOREACH之后的内容(用{}括起来)
 */
for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
{ ;}


/* 使用模板返回相关的指针,用于private class当中,避免void然后强制类型转换
 */
  template <typename T> static inline T *qGetPtrHelper(T *ptr) { return ptr; }
template <typename Wrapper> static inline typename Wrapper::pointer qGetPtrHelper(const Wrapper &p) { return p.data(); }

/*
 * Q_DECLARE_PRIVATE(Class)等宏通过类中的d_ptr和q_ptr实现private class,以实现二进制兼容
 */

/*
 * TODO: QPrivate 中的enable_if还需要了解,可借助 std::enable_if的说明
 */
Avatar_small
fknapredak 说:
2024年10月20日 16:29

This is a interesting line of content, very nice article. Thanks for sharing this post, good way of bring this subject to discussion. Keep up the great work ! crypto Thank you for finding the time to debate this, Personally i think strongly over it and love learning read more about this topic. Whenever possible, when you gain expertise, could you mind updating your blog with extra information? It is very great for me.

Avatar_small
website 说:
2024年10月20日 16:30

I admit, I have not been on this webpage in a long time… however it was another pleasure to see It is such an essential topic and ignored by so numerous, even professionals. I thank you to help making people more aware of possible issueExcellent stuff as typical

Avatar_small
website 说:
2024年10月20日 16:31

The free Mega MP3 Converter app allows you to download Youtube videos to MP3 files up to 320 kbps. It helps you quickly convert your favorite videos to high-quality MP3 files.

Avatar_small
먹휴고 说:
2024年10月20日 16:34

exceptional study, superb website, wherein did u provide you with the statistics in this posting? I have read many of the articles on your website now, and i virtually like your fashion. Thanks a million and please preserve up the effective paintings i trully appretiate your work and recommendations given with the aid of you is beneficial to me. I will proportion this facts with my family & pals. That is a outstanding internet site, hold the high quality critiques coming. That is a excellent inspiring . I am pretty an awful lot thrilled together with your correct work. You put virtually very helpful records. I'm seeking to analyzing your subsequent put up. !!!!

Avatar_small
baccaratfriend 说:
2024年10月20日 16:35

am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work

Avatar_small
read more 说:
2024年10月20日 16:36

Really interesting and special post. I like things such as making more homework, developing writing skills, and also related things. These kinds of secrets help in being a qualified person on this topic. This page is very helpful to myself because people like you committed time to learning. Regularity is the key. But it is not too easy, as has been designed to be. I am not an expert like you and plenty of times I feel really giving it up

Avatar_small
information 说:
2024年10月20日 16:37

Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing.

Avatar_small
website 说:
2024年10月20日 16:37

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work

Avatar_small
here 说:
2024年10月20日 16:39

They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, wome

Avatar_small
메이저토토 说:
2024年10月20日 16:40

hello, i do ass it looks excellent but, if beginning in internet explorer, it has some overlapping troubles. I genuinely preferred to offer you a short heads up! Other than that, superb website! Woah! I am in reality digging the template/difficulty of this net website online. It is easy, but effective. Quite some times it's far difficult to get that "best stability" amongst amazing usability and appearance. I have to say you have carried out a first rate challenge with this. Additionally, the blog loads extremely brief for me on safari. First rate blog i weblog regularly and that i surely recognize your statistics. Your article has definitely peaked my interest. I'm able to ebook mark your weblog and preserve checking for brand spanking new details about as soon as per week. I subscribed for your feed as nicely.

Avatar_small
good contents 说:
2024年10月20日 16:40

simply appreciably greater very a lot desired than you'll be at this moment. You're insightful. You notice along those strains essentially regarding the matter of this concern, delivered me as i would like to think accept as true with it is something however a fantastic deal of fluctuated factors. Its like women and men aren't blanketed besides if it is something to acquire with woman loopy! Your character stuffs wonderful. All of the time manage it up! What is taking spot i'm new to this, i coincidentally found this i've located it completely accommodating and it has assisted me with tour loads.

Avatar_small
contents 说:
2024年10月20日 17:11

 Just admiring your work and wondering how you managed this blog so well. It’s so remarkable that I can't afford to not go through this valuable information whenever I surf the internet

Avatar_small
read more 说:
2024年10月20日 17:13

Laundry Bangkok offers a wide range of professional cleaning services for both residential and commercial customers. Trust us to handle all your laundry needs.

Avatar_small
more info 说:
2024年10月20日 17:18

Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post

Avatar_small
카지노세상 说:
2024年10月20日 17:20

am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work

Avatar_small
here 说:
2024年10月20日 17:28

superb article. Thanks an excessive amount of for the breakdown you've got supplied here. I am still kind-of an illiterate on this topic. So this post becam

Avatar_small
get more info 说:
2024年10月20日 17:31

simply appreciably greater very a lot desired than you'll be at this moment. You're insightful. You notice along those strains essentially regarding the matter of this concern, delivered me as i would like to think accept as true with it is something however a fantastic deal of fluctuated factors. Its like women and men aren't blanketed besides if it is something to acquire with woman loopy! Your character stuffs wonderful. All of the time manage it up! What is taking spot i'm new to this, i coincidentally found this i've located it completely accommodating and it has assisted me with tour loads.

Avatar_small
check here 说:
2024年10月20日 17:33

superb article. Thanks an excessive amount of for the breakdown you've got supplied here. I am still kind-of an illiterate on this topic. So this post becam

Avatar_small
read more 说:
2024年10月20日 17:37

You glaringly canot confront anybody about what you have located if the facts isn't always right

Avatar_small
먹튀마루 说:
2024年10月20日 17:38

Get huge discount on Home and Kitchen Appliances,Split and Window Air Conditioner, Mobiles & Laptops online , Television, Speakers & more electronics at best price

Avatar_small
information 说:
2024年10月20日 17:40

In particular, it´s vital to center around prosperity and politeness while seeking out an Call Girls in Lahore. Look for associations that have an extreme screening process for their escorts, ensuring that they are of genuine age and are providing their administrations willingly. Besides, a genuine association will zero in on the security of their clients, ensuring that all interactions are kept in mystery.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter