|
代码是我写的模拟 手机拨号的 界面: - #include <QtGui/QApplication>
- #include <QtGui/QWidget>
- #include <QtGui/QLabel>
- #include <QtGui/QPushButton>
- #include <QTextEdit>
- #define MWINW 240 //主窗口宽度
- #define MWINH 320 //主窗口高度
- #define KEYW 80 //按钮宽度
- #define KEYH 40 //按钮高度
- class MyPhoneWin : public QWidget
- {
- public:
- MyPhoneWin();
- private:
- QPushButton *b1;
- QPushButton *b2;
- QPushButton *b3;
- QPushButton *b4;
- QPushButton *b5;
- QPushButton *b6;
- QPushButton *b7;
- QPushButton *b8;
- QPushButton *b9;
- QPushButton *b0;
- QPushButton *bA;
- QPushButton *bB;
- QPushButton *bBack;
- QPushButton *bOK;
- QLabel *label;
- QTextEdit *line;
- };
- MyPhoneWin::MyPhoneWin()
- {
- setGeometry(100, 100, MWINW, MWINH);
- setMinimumSize(MWINW, MWINH);
- setMaximumSize(MWINW, MWINH);
- label = new QLabel(this);
- label->setGeometry(0, 0, MWINW, 120);
- label->setText("This is the first line.\nThis is the second line.");
- line = new QTextEdit(this);
- line->setGeometry(0, 0, MWINW, 100);
- b1 = new QPushButton("1", this);
- b2 = new QPushButton("2", this);
- b3 = new QPushButton("3", this);
- b4 = new QPushButton("4", this);
- b5 = new QPushButton("5", this);
- b6 = new QPushButton("6", this);
- b7 = new QPushButton("7", this);
- b8 = new QPushButton("8", this);
- b9 = new QPushButton("9", this);
- b0 = new QPushButton("0", this);
- bA = new QPushButton("*", this);
- bB = new QPushButton("#", this);
- bOK = new QPushButton("OK", this);
- bBack = new QPushButton("Back", this);
- b1->setGeometry(0, 121, KEYW, KEYH);
- b2->setGeometry((1*KEYW-1), 121, KEYW, KEYH);
- b3->setGeometry((2*KEYW-1), 121, KEYW, KEYH);
- b4->setGeometry(0, (121+KEYH*1), KEYW, KEYH);
- b5->setGeometry((1*KEYW-1), (121+KEYH*1), KEYW, KEYH);
- b6->setGeometry((2*KEYW-1), (121+KEYH*1), KEYW, KEYH);
- b7->setGeometry(0, (121+KEYH*2), KEYW, KEYH);
- b8->setGeometry((1*KEYW-1), (121+KEYH*2), KEYW, KEYH);
- b9->setGeometry((2*KEYW-1), (121+KEYH*2), KEYW, KEYH);
- bA->setGeometry(0, (121+KEYH*3), KEYW, KEYH);
- b0->setGeometry((1*KEYW-1), (121+KEYH*3), KEYW, KEYH);
- bB->setGeometry((2*KEYW-1), (121+KEYH*3), KEYW, KEYH);
- bOK->setGeometry(0, (121+KEYH*4), KEYW, KEYH);
- bBack->setGeometry((2*KEYW-1), (121+KEYH*4), KEYW, KEYH);
- connect(b1, SIGNAL(clicked()), line, SLOT(setText("1")));
- connect(b2, SIGNAL(clicked()), line, SLOT(setText("2")));
- connect(b3, SIGNAL(clicked()), line, SLOT(setText("3")));
- connect(bBack, SIGNAL(clicked()), line, SLOT(clear()));
- }
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- MyPhoneWin w;
- w.show();
- return app.exec();
- }
89, 90, 91行是这样的: connect(b1, SIGNAL(clicked()), line, SLOT(setText("1"))); connect(b2, SIGNAL(clicked()), line, SLOT(setText("2"))); connect(b3, SIGNAL(clicked()), line, SLOT(setText("3"))); 但是按键后并 没有执行setText,请问大侠这是怎么回事? 谢谢了。
|