|
共有52人参与查看参与人员 投票限制 - 本投票只允许注册日期大于 2010-11-08 会员投票
投票 辩论结束时间 2014-12-31 14:39 — 裁判: admin #include <QtGui> #include <mymainwindow.h>
mymainwindow::mymainwindow() { setWindowTitle("key choice"); setGeometry(100,100,610,520);
mymain=new QWidget(this); mymain->resize(600,510);
b1=new QPushButton("1",mymain); b1->setGeometry(10,30,100,40); b1->setFont(QFont("Times",18,QFont::Bold));
b2=new QPushButton("2",mymain); b2->setGeometry(10,80,100,40); b2->setFont(QFont("Times",18,QFont::Bold));
b3=new QPushButton("3",mymain); b3->setGeometry(10,130,100,40); b3->setFont(QFont("Times",18,QFont::Bold));
b4=new QPushButton("4",mymain); b4->setGeometry(10,180,100,40); b4->setFont(QFont("Times",18,QFont::Bold));
b5=new QPushButton("5",mymain); b5->setGeometry(10,230,100,40); b5->setFont(QFont("Times",18,QFont::Bold));
b6=new QPushButton("6",mymain); b6->setGeometry(10,280,100,40); b6->setFont(QFont("Times",18,QFont::Bold));
b7=new QPushButton("7",mymain); b7->setGeometry(10,330,100,40); b7->setFont(QFont("Times",18,QFont::Bold));
b8=new QPushButton("8",mymain); b8->setGeometry(10,380,100,40); b8->setFont(QFont("Times",18,QFont::Bold));
b9=new QPushButton("9",mymain); b9->setGeometry(10,430,100,40); b9->setFont(QFont("Times",18,QFont::Bold));
tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500);
addChild(mymain);
connect(b1,SIGNAL(clicked()),this,SLOT(mydisplay1())); connect(b2,SIGNAL(clicked()),this,SLOT(mydisplay2())); connect(b3,SIGNAL(clicked()),this,SLOT(mydisplay3())); connect(b4,SIGNAL(clicked()),this,SLOT(mydisplay4())); connect(b5,SIGNAL(clicked()),this,SLOT(mydisplay5())); connect(b6,SIGNAL(clicked()),this,SLOT(mydisplay6())); connect(b7,SIGNAL(clicked()),this,SLOT(mydisplay7())); connect(b8,SIGNAL(clicked()),this,SLOT(mydisplay8())); connect(b9,SIGNAL(clicked()),this,SLOT(mydisplay9()));
} void mymainwindow::mydisplay1() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setReadOnly(true);
QFile myfile("e:/mymainwindow/1.tex"); myfile.open(IO_ReadOnly); QTextStream mystream(&myfile); QString mystring; while(mystream.atEnd()==0) { mystring=mystream.readLine(); tedit->insertLine(mystring); } myfile.close(); }
void mymainwindow::mydisplay2() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the second choice of text."); tedit->show(); }
void mymainwindow::mydisplay3() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the third choice of text."); tedit->show(); }
void mymainwindow::mydisplay4() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the fourth choice of text."); tedit->show(); }
void mymainwindow::mydisplay5() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the fifth choice of text."); tedit->show(); }
void mymainwindow::mydisplay6() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the sixth choice of text."); tedit->show(); }
void mymainwindow::mydisplay7() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the seventh choice of text."); tedit->show(); }
void mymainwindow::mydisplay8() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the eighth choice of text."); tedit->show(); }
void mymainwindow::mydisplay9() { tedit=new Q3MultiLineEdit(mymain); tedit->setGeometry(120,0,500,500); tedit->setText("This is the ninth choice of text."); tedit->show(); }
按按钮1没反应
但是单独的程序#include <QApplication> #include <QWidget> #include <QFile> #include <QTextStream> #include <QString> #include <Qt3Support/Q3MultiLineEdit>
class twelve1:public QWidget { public: twelve1(); private: Q3MultiLineEdit *medit; };
twelve1::twelve1() { setGeometry(100,100,480,400);
medit=new Q3MultiLineEdit(this); medit->setGeometry(10,10,460,380); medit->setReadOnly(true);
QFile myfile("e:/mymainwindow/1.txt");//文件的路径
myfile.open(IO_ReadOnly);//设置为只读模式
QTextStream mystream(&myfile);//这个对象从文件中读取文本
QString mystring;
while(mystream.atEnd()==0)//从文件中读取一行,并将它输出到QMultiLineEdit对象。 { mystring=mystream.readLine();//readline()每次只读一行,而read()读取整个流
medit->insertLine(mystring);
}
myfile.close();
}
void main(int argc,char **argv) { QApplication a(argc,argv); twelve1 w; w.show(); a.exec(); }
可以显示。txt中的内容,为什么跟按钮在一起了就没用
|
请高手指教!
|