82.QT实现委托构造

 1 #include "mainwindow.h"
 2 #include <QApplication>
 3 
 4 //创建一个MainWindow类
 5 class myclass
 6 {
 7 private:
 8     MainWindow *p;
 9     //初始化内存
10     myclass(int i)
11     {
12         p = new MainWindow[i];
13     }
14 
15 public:
16     //设置显示
17     myclass(int i,int j):myclass(i)
18     {
19         if(j == 0)
20         {
21             for(int k=0;k<i;k++)
22             {
23                 p[k].show();
24             }
25         }
26         else
27         {
28             for(int k=0;k<i;k++)
29             {
30                 p[k].resize(100,100);
31                 p[k].show();
32             }
33         }
34     }
35 
36     //设置颜色
37     myclass(int i,double k):myclass(i)
38     {
39         for(int j=0;j<i;j++)
40         {
41             QPalette pl(p[j].palette());
42             pl.setColor(QPalette::Background,Qt::yellow);
43             p[j].setPalette(pl);
44             p[j].show();
45         }
46     }
47 
48     //设置窗口标题
49     myclass(int i,double k,char *str):myclass(i,k)
50     {
51         for(int j=0;j<i;j++)
52         {
53             p[j].setWindowTitle(str);
54         }
55     }
56 };
57 
58 int main(int argc, char *argv[])
59 {
60     QApplication a(argc, argv);
61     //MainWindow w;
62     //w.show();
63     myclass my1(3,1.0,"mywindow");
64 
65     return a.exec();
66 }
原文地址:https://www.cnblogs.com/xiaochi/p/8586249.html