dreamer's house

Hold fast to dream, for if dream dies, life is a broken-winged bird that can't fly


Joe @ 2007-04-15 17:29

实在是太慢了,每次都打不开编辑器,简单的又太挫了~~



 
Joe @ 2007-03-22 10:45

    很早就打算写几篇介绍Qt核心机制的文章了,也已近答应了Forrest,不过一直没有时间。最近几天一直在做Linux相关的东西,还是再等等吧。这是官方的说明

Meta-Object System

Qt's Meta-Object System provides the signals and slots mechanism for inter-object communication, run-time type information, and the dynamic property system.

The Meta-Object System is based on three things:

  1. The QObject class provides a base class for objects that can take advantage of the meta-object system.
  2. The Q_OBJECT macro inside the private section of the class declaration is used to enable meta-object features, such as dynamic properties, signals, and slots.
  3. The Meta-Object Compiler (moc) supplies each QObject subclass with the necessary code to implement meta-object features.

The moc tool reads a C++ source file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces another C++ source file which contains the meta-object code for each of those classes. This generated source file is either #include'd into the class's source file or, more usually, compiled and linked with the class's implementation.

In addition to providing the signals and slots mechanism for communication between objects (the main reason for introducing the system), the meta-object code provides the following additional features:

It is also possible to perform dynamic casts using qobject_cast() on QObject classes. The qobject_cast() function behaves similarly to the standard C++ dynamic_cast(), with the advantages that it doesn't require RTTI support and it works across dynamic library boundaries. It attempts to cast its argument to the pointer type specified in angle-brackets, returning a non-zero pointer if the object is of the correct type (determined at run-time), or 0 if the object's type is incompatible.

For example, let's assume MyWidget inherits from QWidget and is declared with the Q_OBJECT macro:

     QObject *obj = new MyWidget;

The obj variable, of type QObject *, actually refers to a MyWidget object, so we can cast it appropriately:

     QWidget *widget = qobject_cast<QWidget *>(obj);

The cast from QObject to QWidget is successful, because the object is actually a MyWidget, which is a subclass of QWidget. Since we know that obj is a MyWidget, we can also cast it to MyWidget *:

     MyWidget *myWidget = qobject_cast<MyWidget *>(obj);

The cast to MyWidget is successful because qobject_cast() makes no distinction between built-in Qt types and custom types.

     QLabel *label = qobject_cast<QLabel *>(obj);
// label is 0

The cast to QLabel, on the other hand, fails. The pointer is then set to 0. This makes it possible to handle objects of different types differently at run-time, based on the type:

     if (QLabel *label = qobject_cast<QLabel *>(obj)) {
label->setText(tr("Ping"));
} else if (QPushButton *button = qobject_cast<QPushButton *>(obj)) {
button->setText(tr("Pong!"));
}

While it is possible to use QObject as a base class without the Q_OBJECT macro and without meta-object code, neither signals and slots nor the other features described here will be available if the Q_OBJECT macro is not used. From the meta-object system's point of view, a QObject subclass without meta code is equivalent to its closest ancestor with meta-object code. This means for example, that QMetaObject::className() will not return the actual name of your class, but the class name of this ancestor.

Therefore, we strongly recommend that all subclasses of QObject use the Q_OBJECT macro regardless of whether or not they actually use signals, slots, and properties.

See also QMetaObject, Qt's Property System, and Signals and Slots.




 
Joe @ 2007-03-17 18:24

    It's a common question for most new learners of Java: What's java bean? This concept is repeated for so many times at so many places by so many different people, but what on earth is it?
    At the simplest, if an object has setters and getters for its attributes, then it's a bean. This simple bean only provides support for properties, which is one of the features specified in JavaBean's specification. A java bean is not defined by a set of interfaces, but some basic concepts or functionalities.
    The initial definition given by Sun is like this:A Java Bean is a reusable software component that can be manipulated visually in a builder tool. Well, it's still two abstract for us to understand. Let's make a comparision, if you know COM and what's COM used for, then you can assume that Bean play the same role in Java world. With COM, we can put different kinds of documents together in a browser or in word editor. And in java, we have applets and awt.Component. For a full featured bean, it should support introspection,customization,events,properties and persistence.To understand why we need these features, we can see how we do in a GUI designer, we first drag a component to the background, then set its properites , and add some events. When we run the program, the component can work well with the main frame. In Qt, we can customize our own widget and add it to the toolbar, the frame can analyze the widget to see if it can work correctly in the framework. This is introspection. In .NET framework 2.0 we have datagridview control, which can read from datasource automatically. So we need persisitence.
    So if you know some details about java bean, you will find many similar stuff which you may have known before. At least that's what I have known about JavaBean.
    To know more about JavaBean, download a specification from Sun's site.
    If you find anything wrong from above, just tell me, I am glad to hear your voice.



 
Joe @ 2007-03-14 16:34

用javascript写的星际争霸,的确很牛。http://www.script8.com/works/sc/index.htm



 
Joe @ 2007-03-12 19:30

看完论语心得之后对其中讲的一些道理颇有感触。孔子推崇安于贫贱,这个观点对于现代人来说似乎太过于不可接受,尤其在一个几乎以金钱和名利作为个人成功标志的社会。字面上看,安于贫贱的确不是我们可以接受的想法,但是仔细想想,何为贫贱?于贫贱相对的是富贵,富贵乃众人之所欲也。想想身边的人,有的选择出国,有的考研,有的考公务员,不管选择什么,大多是为了选择一个好的前途,很多人不知道自己为什么去走这条路,只是为了一个得到一个被众人所推崇的“前途"。这个大抵便是不安于”贫贱“,而去追逐”富贵“之道吧。 在我看来,安于贫贱即是抛弃整个社会的大多数人强加在自己身上的一种包袱,身在这个社会之中,却能够给自己留出一份安逸的天地,让自己的思想能够在这在自由的驰骋。众人为富所动,而吾则偏爱自由之道。安于贫贱是一种心态,一种能够让自己拥有独立于社会的个人意志的一种境界。贫贱与富贵是他人之所欲和所不欲,而不不是一个”安于贫贱“的人所关心的东西。 我的理解大抵如此。


 
Joe @ 2007-03-01 11:54

   昨天花了一天时间完成了 Herbert的模拟程序。在release方式下测试的结果是3s可以运行10万次,比预计的要差,不过也基本可以满足需求了吧,接下来只要写一个好的生成策略,就可以全天候运行了。代码在3月底再公开吧。不过为了尽可能的快一些,用了许多bt的方法。(注,原先由于一个bug,所以把时间弄错了)



 
Joe @ 2007-02-27 20:26

    在拥有了集成到VS2003的Qt以后,应该来仔细的体验一下Qt的方便之处了。所以尝试做了一个CountTool。
    如果用MFC做我不知道自己可不可在一天多的时间里做完。不过用Qt的确很方便,虽然以前基本没有用Qt做过什么东西,对它的API并不是很熟悉,但是凭着一个帮助文档,就这样边查边做,倒也做得很快。如果之前喜欢Qt只是凭着一种感觉,这之后就更有信心了。
    这个CountTool的主要功能已经完成了,除了一些细节没有完成。自己也不打算做到Perfert了。代码总量有500多行。
    恩,详细的也就不多说了,如果想知道Qt到底如何还是自己亲自去体验吧。
    源代码下载:joehust.googlepages.com/CountExpert.rar
    可执行文件:joehust.googlepages.com/CountExpert.exe



 
Joe @ 2007-02-26 19:57

    Warning: The method introduced below can only be used for personal study, other illegal use will be on your responsibility.

Introduction:

    The Qt Visual Studio Integration is a great help for programmers who wants to use Qt with VS. It's also a good choice for those  programmers who find MFC too inperfect . Personally I will suggest all the new programmers to learn Qt instead of MFC. There are ways to compile an open-source edition of Qt with VS, which you also can find from other sites. But how to use the Qt Visual Integration is not yet discussed much.  There is a Evaluation edtion which you can download free from Qt's site, but the programs will always show some mark showing it's compiled with an evalution edtion, which can not be used for some practical purposes.

Prerequisites:
   VS2003(Vs2005 has not been tried, but should work in the same way),
   Qt-Open-Source-Edition, you can download it from Qt's site
   An unofficial patch for Qt of your version, you can get one from sourceforge.net/projects/qtwin/%20
   the newest versin supports qt 4.2.2

Steps:

    1.
unzip your qt-open-source-editin to a suitable directory. Suitable means two points. First,there is enough disk space left for compilation and second, you have to install your Qt integration to the same directory later.
    2. unpatch your patch to the directory you selected in the last step.
    3. Run vcvars32.bat in command line mode. You can find this program at Microsoft Visual Studio 2003\VC\bin\vcvars32.bat.
    4. run qconfigure.bat msvc.net ( if you have anything not clear, see the instructions said in the patch's readme file)
    5. after that run nmake in command line. If you have not add VS2003's bin directory into your path, set it.
    6. just wait for several hours, it depends on your machine how long you have to wait.
    7. now change the name of the folder you use to put your qt-open-source files.
    8. get an evaluation edition from Qt's site and get a name and licence key.
    9. install the first qt part to exactly the same directory you used just now.
    10. after that copy all the files from your qt open source folder's bin directory to override the file in the Qt's evaluation's bin.
    11. search the pdb files you have compiled just now and copy them to your qt evaluation' bin.
    12. copy the src to qt evaluation's bin, before you do that you may want to delete all the obj files and pch files.

    Now enjoy your qt with vs2003.
 
 
   



 
网志分类
· 所有网志 (46) · 算法 (4) · C++ (7) · 随笔 (16) · Java (1) · javascript (3) · 编程开发 (9) · Python (4) · 未分类 (2) ·
最新的评论
站内搜索
友情链接
· 我的歪酷 非非共享界 · Realdodo · Bruce Eckel

订阅 RSS

0027902

歪酷博客