jump to navigation

C++ Class 繼承 17 四月, 2007

Posted by leterboy in Learning QT.
5 comments

今天要討論的是  C++ 如何寫 Class繼承

將ABC繼承 Class DEF

a.h 

class DEF{
public:
    DEF(int aaa);
    DEF();
    int m_aaa;
};
class ABC : public DEF{
public:
    ABC(int d);   
    int m_aValue;

};

a.cpp

#include “a.h"

ABC::ABC(int d):DEF(d)
{
        m_aValue=d;
}
DEF::DEF()
{
}
DEF::DEF(int aaa)
{
    m_aaa=aaa;
}

由於我們在QT底下測試,那就用個QPushButton顯示好了
main.cpp
#include <QApplication>
 #include <QPushButton>
 #include “a.h"

 int main(int argc, char *argv[])
 {

     QApplication app(argc, argv);

    ABC *abc=new ABC(30);
    QString s = QString::number(abc->m_aValue);
     QPushButton hello(s);
     hello.resize(100, 30);

     hello.show();
     return app.exec();
 }

Powered by ScribeFire.

The Central Widget 19 三月, 2007

Posted by leterboy in Learning QT.
add a comment

在一個視窗程式中,最主要的Central Widget,可能有以下幾種方式產生
(資料來源:Programming with Qt 4, ISBN:0-13-187249-4 )

  1. 使用標準 Qt Widget,例如:QTableWidget、QTextEdit
  2. 使用自訂的Widget
  3. 擁有許多不同的widget,使用plain QWidget搭配layout manager,可以使用QWidget為其他widget的parent,並且使用layout manager管理版面
  4. 使用spiltter:另一種使用多個widget的方式,就是使用QSplitter來做sizing control
  5. 使用MDI workspace:若應用程式採用MDI,則central widget應該是QWorkspace widget,而每一個MDI windows則是這個widget的child。

powered by performancing firefox