QT开发平台

草根聪 草根聪 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在ubuntu下面安装了一个QT开发工具,但是后面进入QT Creator后,直接运行example都不行,我主要目的是
在源文件有的情况下,可以运行出一个出来,这是一个的猜数字游戏(网上下载的)
main.cpp

#include <QApplication>
#include "newfile.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
mywidget win;
win.show();

return app.exec();
}

newfile.cpp

#include <QtGui>


#include "newfile.h"

mywidget::mywidget(QWidget* parent):QWidget(parent)
{
label=new QLabel("time:");
addButton=new QPushButton("Input");
newButton=new QPushButton("New");
edit=new QLineEdit();
edittime=new QLineEdit("1");
edittime->setReadOnly(true);
val = rand() % 99 + 0;
time=1;
connect( addButton,SIGNAL(clicked()),this,SLOT(estimate()));
connect( newButton,SIGNAL(clicked()),this,SLOT(newgame()));

QHBoxLayout *HLayout = new QHBoxLayout;
HLayout->addWidget(label);
HLayout->addWidget(edittime);

QVBoxLayout *VLayout = new QVBoxLayout;
VLayout->addLayout(HLayout);
VLayout->addWidget( edit);
VLayout->addWidget(addButton);
VLayout->addWidget(newButton);
setLayout(VLayout);
setWindowTitle(QObject::trUtf8("猜数字了"));//设置标题
}
void mywidget::estimate()
{ QString stemp;

float ltemp;
ltemp=edit->text().toFloat();
stemp=QString::number(time);
edittime->setText(stemp);
time++;
if(ltemp>val)
{
QMessageBox::about(this, tr("Message"),
QObject::trUtf8("<h2>大了</h2>"));


}
if(ltemp<val)
{
QMessageBox::about(this, tr("Message"),
QObject::trUtf8("<h2>小了</h2>"));

}
if(ltemp==val)
{
QMessageBox::about(this, tr("Message"),
QObject::trUtf8("<h2>猜对了!!</h2>"));

}

}
void mywidget::newgame()
{
QString stemp;
time=1;
stemp=QString::number(time);
edittime->setText(stemp);
edit->setText("");
val = rand() % 99 + 0;

}

newfile.h

#ifndef __NEWFILE_H__
#define __NEWFILE_H__
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QApplication>
#include <QLabel>
#include <QObject>
class QLineEdit;
class QTextEdit;
class QPushButton;


class mywidget:public QWidget
{

Q_OBJECT

public:
mywidget(QWidget* parent=0);
private slots:
void estimate();
void newgame();
private:
QPushButton* addButton;
QPushButton* newButton;
QLabel* label;
QLineEdit *edittime;
QLineEdit *edit;
int val ;
int time;
};
#endif // __NEWFILE_H__


如果安装了LinuxQT的大神,希望能帮我建立一个工程,把工程打包发送给我一下,谢谢了,或者曾经做的小游戏发送给我也行。非常感谢。邮箱1971445763@qq.com
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
草根聪
Linux/Unix社区 23,224 成员 74,535 内容