?? mywidget.cpp
字號:
/* Copyright ADBON. All rights reserved. * file MyWidget.cpp is software of phone program; * author Bing Ning. * See http://www.adbon.com.cn *///qt include#include<qpushbutton.h>#include<qlineedit.h>#include<qstring.h>#include<qcstring.h>#include<qapplication.h>//system include#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<fcntl.h>#include<termios.h>#include<sys/times.h>#include<sys/types.h>#include<sys/ioctl.h>#include<string.h>//my include#include"MyWidget.h"//#include"MyCom.h"static int fdcom;static int send_flag = 0;const QString ATD = "ATD";const QString AT1 = ";\r";QString phone_buf;//QCString phone_buffer;//int i;//QByteArray buffer;MyWidget::MyWidget(QWidget *parent, const char *name):QWidget(parent, name){ setMinimumSize(100, 220); setMaximumSize(100, 220); QPushButton *button_1 = new QPushButton("1", this, "button_1"); button_1->setGeometry(10, 80, 25, 25); button_1->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_2 = new QPushButton("2", this, "button_2"); button_2->setGeometry(40, 80, 25, 25); button_2->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_3 = new QPushButton("3", this, "button_3"); button_3->setGeometry(70, 80, 25, 25); button_3->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_4 = new QPushButton("4", this, "button_4"); button_4->setGeometry(10, 115, 25, 25); button_4->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_5 = new QPushButton("5", this, "button_5"); button_5->setGeometry(38, 115, 25, 25); button_5->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_6 = new QPushButton("6", this, "button_6"); button_6->setGeometry(68, 115, 25, 25); button_6->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_7 = new QPushButton("7", this, "button_7"); button_7->setGeometry(8, 150, 25, 25); button_7->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_8 = new QPushButton("8", this, "button_8"); button_8->setGeometry(38, 150, 25, 25); button_8->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_9 = new QPushButton("9", this, "button_9"); button_9->setGeometry(68, 150, 25, 25); button_9->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_0 = new QPushButton("0", this, "button_0"); button_0->setGeometry(38, 185, 25, 25); button_0->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_11 = new QPushButton("*", this, "button_11"); button_11->setGeometry(8, 185, 25, 25); button_11->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_12 = new QPushButton("#", this, "button_12"); button_12->setGeometry(68, 185, 25, 25); button_12->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_send = new QPushButton("ok", this, "send"); button_send->setGeometry(8, 45, 25, 25); button_send->setFont(QFont("Times", 18, QFont::Bold)); QPushButton *button_quit = new QPushButton("quit", this, "button_quit"); button_quit->setGeometry(68, 45, 25, 25); button_quit->setFont(QFont("Times", 12, QFont::Bold)); QPushButton *button_c = new QPushButton("C", this, "button_c"); button_c->setGeometry(38, 45, 25, 25); button_c->setFont(QFont("Times", 18, QFont::Bold)); phone_edit = new QLineEdit(this); phone_edit->setGeometry(8, 20, 85, 15); phone_edit->setReadOnly(TRUE); //test line qlineedit_test = new QLineEdit(this); qlineedit_test->setGeometry(8, 3, 85, 15); //test line end! connect(button_1, SIGNAL(clicked()), this, SLOT(insert_1())); connect(button_2, SIGNAL(clicked()), this, SLOT(insert_2())); connect(button_3, SIGNAL(clicked()), this, SLOT(insert_3())); connect(button_4, SIGNAL(clicked()), this, SLOT(insert_4())); connect(button_5, SIGNAL(clicked()), this, SLOT(insert_5())); connect(button_6, SIGNAL(clicked()), this, SLOT(insert_6())); connect(button_7, SIGNAL(clicked()), this, SLOT(insert_7())); connect(button_8, SIGNAL(clicked()), this, SLOT(insert_8())); connect(button_9, SIGNAL(clicked()), this, SLOT(insert_9())); connect(button_0, SIGNAL(clicked()), this, SLOT(insert_0())); connect(button_11, SIGNAL(clicked()), this, SLOT(insert_11())); connect(button_12, SIGNAL(clicked()), this, SLOT(insert_12())); connect(button_quit, SIGNAL(clicked()), this, SLOT(lineedit_clear())); connect(button_c, SIGNAL(clicked()), this, SLOT(lineedit_backspace())); connect(button_send, SIGNAL(clicked()), this, SLOT(data_send_com())); }MyWidget::~MyWidget(){}void MyWidget::insert_1(){ phone_edit->insert("1");} void MyWidget::insert_2(){ phone_edit->insert("2");}void MyWidget::insert_3(){ phone_edit->insert("3");}void MyWidget::insert_4(){ phone_edit->insert("4");}void MyWidget::insert_5(){ phone_edit->insert("5");}void MyWidget::insert_6(){ phone_edit->insert("6");}void MyWidget::insert_7(){ phone_edit->insert("7");}void MyWidget::insert_8(){ phone_edit->insert("8");}void MyWidget::insert_9(){ phone_edit->insert("9");}void MyWidget::insert_0(){ phone_edit->insert("0");}void MyWidget::insert_11(){ phone_edit->insert("*");}void MyWidget::insert_12(){ phone_edit->insert("#");}void MyWidget::lineedit_backspace(){ phone_edit->backspace();}void MyWidget::lineedit_clear(){}void MyWidget::data_send_com(){ int send_len, recv_len; char recv_buf[10]; char send_buf[30]; memset(recv_buf, 0, 10); memset(send_buf, 0, 30); /*portinfo_t portinfo = { '0', // print prompt after receivong 115200, // baudrate: 115200 '8', // databit: 8 '0', // debug :off '0', // echo: off '0', // flow control: no '1', // default tty: COM2 '0', // parity: none '1', // stopbit : 1 0 // reserved }; fdcom = PortOpen(&portinfo); if(fdcom < 0) { printf("Error: open serial port error.\n"); exit(-1); } PortSet(fdcom, &portinfo); */ phone_buf = ATD + phone_edit->text() + AT1; qlineedit_test->setText(phone_buf); memcpy(send_buf, phone_buf, phone_buf.length()); printf("the send_buf is %s . \n",send_buf); //send data to com// send_len = PortSend(fdcom, send_buf, strlen(send_buf)); if(send_len > 0) { send_flag = 1; printf("Send data to %d com OK!\n", send_len); } else { printf("Error: send failed!\n"); } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -