QT开发平台

草根聪 2012-11-26 04:08:44
我在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
...全文
113 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zodiac1111 2012-11-26
  • 打赏
  • 举报
回复
仔细点吧 qmake -project不是qmake-project
引用 2 楼 cangencong 的回复:
引用 1 楼 zmlovelx 的回复:三个文件放在一个文件夹下面. qmake -project 生成工程文件 然后 qmake生成Makefile make编译 我安装了QT,如下 但是我的安装目录下的bin中 没有qmake-project命令,只有qmake呀。谢谢你的帮助
草根聪 2012-11-26
  • 打赏
  • 举报
回复
引用 1 楼 zmlovelx 的回复:
三个文件放在一个文件夹下面.
qmake -project
生成工程文件
然后
qmake生成Makefile
make编译

我安装了QT,如下

但是我的安装目录下的bin中

没有qmake-project命令,只有qmake呀。谢谢你的帮助
帅得不敢出门 2012-11-26
  • 打赏
  • 举报
回复
三个文件放在一个文件夹下面. qmake -project 生成工程文件 然后 qmake生成Makefile make编译

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧