程序的打包发布
利用Qt Creator自带的windeployqt 工具,是非常的方便的,
只要新建一个testname,将release版本的可执行文件xxx.exe放到这个新建文件夹testname中,
然后打开在开始菜单—>Qt 5.3—>MinGW 4.8 (32-bit)—>Qt 5.3 for Desktop (MinGW 4.8 32 bit)的命令窗口:
进入到 d:/qt_release
在命令窗口中输入:windeployqt xxx.exe,回车。
即可将所有需要的dll动态库文件拷贝到testname文件夹中,一下子就ok了。
输入命令:
d:
cd qt_release
calculator.exe
3.安装软件 Nullsoft Install System 并运行软件
Nullsoft Install System -> HW VNISEdit -> 文件 ->新建脚本向导
窗体的类型:
Qt::WindowFlags f = Qt::WindowFlags()
Qt::Widget: This is the default type for QWidget.
Qt::Window : 也是一种显示的窗体
Qt::Dialog : 这个是对话框
Qt::SplashScreen : 没有边框的窗体,类似全屏的显示
new QWidget(0,Qt::Dialog ); 对话窗体有边框
new QWidget(0,Qt::Dialog|Qt::FramelessWindowHint ); 对话窗体没有边框
new QWidget(0,Qt::SplashScreen);欢迎屏幕
new QWidget(0,Qt::SplashScreen|Qt::WindowStaysOnTopHint);欢迎屏幕 保持屏幕在最顶端
关于屏幕坐标的认定,是按照左上角做为起始点
0-----------------> x方向 逐步增加的
|
|
|
|
|
↓
Y方向
带边框的一套函数 :x(), y(),
不带边框的一套函数: 所有的功能都不包含标题栏 qDebug(),用来向屏幕输出字符 Qdialog 这个是对话框类 这个类有被很多子类继承 class app : public QWidget public: private: class Ui_app }; namespace Ui { app的构造函数实现: 设置一个对象的名称可以使用 void setObjectName(const QString &name) button_color_dialog->setObjectName(QStringLiteral(“button_color_dialog”)); 修改应用程序的标题 也可以使用图形化界面设置的方式进行设置: 设置信号的发送与接收,把两者进行捆绑 QMetaObject::Connection connect(const QObject *sender, const char *signal, 获取颜色的对话框 QColorDialog QErrorMessage 错误提示对话框 QFontDialog 字体选择对话框 bool ok; } } QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false) fileName = QFileDialog::getOpenFileName(this, QString getOpenFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), caption : 左上角显示的文字 例如: qDebug()<<“文件名:”<< fileName; 显示: Static functions are available for creating information(), question(), warning(), and critical() message boxes. int ret = QMessageBox::warning(this, tr(“My Application”), QProgressDialog progress(“Copying files…”, “Abort Copy”, 0, numFiles, this); 在qt中一个系统的图标文件使用一个QIcon 去表示 构造函数: 设置图标的第一种方式: 设置图标的第二种方法:直接使用setWindowIcon 19.QLineEdit 用于一行文本的输入和显示 QLineEdit::Normal 0 Display characters as they are entered. This is the default. QDateTimeEdit 用来获取和设置日期和时间 QPlainTextEdit 没有格式的文本输入与显示 在进行编程时,我们经常需要用到字符串这种类型,毫无疑问,Qt 库中也对字符串类型进行了封装,QString 类提供了你能想到的所有字符串操作方法,给开发者带来了极大方便。 下面分两种情况进行说明。 一、QString 转换为 char * 将 QString 转 char *,需要用到 QByteArray 类,QByteArray 类的说明详见 Qt 帮助文档。 方法如下: QString str; 打印文本 QPrinter 和 QPrintDialog QPrinter printer; 帮助提示, 和关于qt void about(QWidget *parent, const QString &title, const QString &text) // 软件的帮助信息 void aboutQt(QWidget *parent, const QString &title = QString()) // 关于qt的表述 因为图片存在 icons/logo1 在使用在使用nsis发布软件时 如果快捷方式没有图片的解决办法: qt中处理图片的类有 QImage, QPixmap, QBitmap and QPicture QImageReader QImageWriter QPixmap QImage Warning: “No decoder available for type ‘audio/mpeg, mpegversion=(int)1, mpegaudioversion=(int)1, layer=(int)3, rate=(int)44100, channels=(int)2,parsed=(boolean)true’.” sudo add-apt-repository ppa:mc3man/gstffmpeg-keep 或则 : sudo apt-get install gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav qDebug()< QSqlDatabase db = QSqlDatabase::addDatabase(“QSQLITE”);创建一个sqllite3数据库 30 . 执行一条sql语句 QSqlQuery
geometry : 几何结构
qDebug()<<“外框宽度:”
qDebug()<<“外框信息: “<<”(”<
qDebug()<<“内框信息: “<<”(”<
w->geometry().getRect(&x,&y,&ww,&h);
qDebug()<<“外框信息: “<<”(”<
qDebug()<<“内框信息: “<<”(”<
QColorDialog : 颜色对话框
QErrorMessage : 错误提示对话框
QFileDialog : 文件对话框
QFontDialog : 字体对话框
QInputDialog : 输入对话框
QMessageBox : 消息提示对话框
QProgressDialog : 进度条对话框
(1). app w; 创建一个类对象, app的定义如下:
{
Q_OBJECT
explicit app(QWidget *parent = 0); // 构造函数
~app();
Ui::app *ui; // ui 是Ui::app的类指针
};
2. Ui::app这个类的定义在哪里
namespace Ui {
class app;
}
这个地方是类的声明
有由app.ui这个文件 是有xml语言实现的, 这个文件由系统的一个工具, 把xml语言转换成一个头文件
qt_18071\day1\build-dialog-Desktop_Qt_5_6_1_MinGW_32bit-Debug\ui_app.h
3. 在app.c 中包含了这个头文件 ui_app.h
{
public:void setupUi(QWidget *app)
{
if (app->objectName().isEmpty())
app->setObjectName(QStringLiteral("app"));
app->resize(600, 400);
app->setMinimumSize(QSize(600, 400));
app->setMaximumSize(QSize(600, 400));
retranslateUi(app);
QMetaObject::connectSlotsByName(app);
} // setupUi
void retranslateUi(QWidget *app)
{
app->setWindowTitle(QApplication::translate("app", "app", 0));
} // retranslateUi
class app: public Ui_app
{
};
} // namespace Ui
setWindowTitle 设个函数的功能是设置 应用程序的名称
app.ui 文件中, qwidget 中找到 windowstitle 这个选项, 之后写入应用程序的名称即可
类似linux 的信号与信号处理函数
第一种: connect , 这个函数是属于 QObject::connect()的静态方法
const QObject *receiver, const char *method,
Qt::ConnectionType type = Qt::AutoConnection)
QColorDialog::getColor(Qt::black,this).getRgb(&r,&g,&b);
qDebug()<<“r:”<
QString str = “应用程序核心错误”;
QErrorMessage *errorp =new QErrorMessage();
errorp->resize(300,100);
errorp->showMessage(str);
The QFontDialog class provides a dialog widget for selecting a font.
If the user clicks OK, the selected font is returned. If the user clicks Cancel, the initial font is returned.
QFont font = QFontDialog::getFont(&ok, QFont(“Helvetica [Cronyx]”, 10), this);
if(ok)
{
qDebug()<<“点击了OK,选择了字体,字体为:”<
else
{
qDebug()<<“点击了Canceled,没有选择字体,使用默认字体”;
程序输出:
点击了OK,选择了字体,字体为: QFont( “微软雅黑,12,-1,5,50,0,0,0,0,0” ) bool ok;
QFont font = QFontDialog::getFont(&ok, QFont("Helvetica [Cronyx]", 10), this);
if(ok)
{
qDebug()<<"点击了OK,选择了字体,字体为:"<
tr(“Open Image”), “/home/jana”, tr(“Image Files (*.png *.jpg *.bmp)”));
const QString &dir = QString(), const QString &filter = QString(),
QString *selectedFilter = Q_NULLPTR, Options options = Options())
dir : 默认要打开的目录
filter : 要打开什么类型的文件
QString fileName = QFileDialog::getOpenFileName(this, tr(“Open File”),
tr(“C:/Users/ShengLi-IBM/Documents”),
tr(“txt (*.txt *.c *.jpg .)”));
文件名: “E:/ShengLi/01-Teaching/讲课笔记/18071/01-c_base/1基础知识.pdf”
tr(“The document has been modified.\n”
“Do you want to save your changes?”),
QMessageBox::Save | QMessageBox::Discard
| QMessageBox::Cancel,
QMessageBox::Save);
构造函数:
QProgressDialog(const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags())
progress.setWindowModality(Qt::WindowModal); for (int i = 0; i < numFiles; i++) {
progress.setValue(i);
if (progress.wasCanceled())
break;
//... copy one file
}
progress.setValue(numFiles);
QIcon(const QString &fileName)
fileName: 要打开的文件名
(1)右击工程->添加新文件 ->Qt -> Qt resource file -> 下一步 -> 填入资源名称
(2)右击新建的资源文件-> 添加现有文件-> 找到文件打开
(3)打开ui文件,找到QWidget->Windows Icon ->normal on -> 单机右边空白部分,-> 点击… -> 选择图片即可
this->setWindowIcon(QIcon(":/icons/png-0007.png"));
(1)可以通过setText() or insert() 来改变文本的内容
(2)获取里面的内容 使用: text()
(3)当里面的文本发生改变时, 有一个信号被发送 textChanged()
(4)当里面的文本中光标移动时, 也会发送给一个信号 cursorPositionChanged()
(5)行光标选中这个输入框时, returnPressed() 信号被发送
(6)当输入完成时,光标移出输入框时, editingFinished() 信号被发送
(7)可以设置显示模式,setEchoMode(EchoMode)
QLineEdit::NoEcho 1 Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.
QLineEdit::Password 2 Display platform-dependent password mask characters instead of the characters actually entered.
QLineEdit::PasswordEchoOnEdit 3 Display characters as they are entered while editing otherwise display characters as with Password.
(1) 获取日期 date() , 设置日期setDate()
(2)Qt QDateEdit 设置下拉日历:
通过成员函数setCalendarPopup(bool)设置一下属性,就可以使其以日历的方式显示
QDateEdit date = new QDateEdit();
date->setCalendarPopup(true);
(1)设置显示内容: setPlainText()
(2)插入文本 insertPlainText(),appendPlainText() or paste().
(3)获取文本 toplainText()
(4) 文本发生改变时。会发送一个信号 textChanged()
但是我们在编写程序时,不可避免地会在 Qt 框架上使用第三方的开源库,由于库的类型基本上都是标准的类型,即使用 char * 来表示字符串类型。那么问题来了,QString 和 char * 之间如何进行转换呢?
因为 char * 最后都有一个’\0’作为结束符,而采用 QString::toLatin1()// 不支持中文
QString::toUtf8()
时会在字符串后面加上’\0’。
char* ch;
QByteArray ba = str.toUtf8(); // must
ch=ba.data();
QPrintDialog printDialog(&printer,this);
if (printDialog.exec() == QDialog::Accepted)
{
ui->plainTextEdit->print(&printer);
}
在成功的.pro文件中,加入一句话:
RC_ICONS +=icons/logo1.ico // 图片路径
在使用nsis发布软件时 让快捷方式也有图标的实现方式
修改脚本中的 :CreateShortCut “KaTeX parse error: Expected 'EOF', got '\notepad' at position 8: DESKTOP\̲n̲o̲t̲e̲p̲a̲d̲.lnk" "INSTDIR\note.exe”
改为:
CreateShortCut “KaTeX parse error: Expected 'EOF', got '\notepad' at position 8: DESKTOP\̲n̲o̲t̲e̲p̲a̲d̲.lnk" "INSTDIR\note.exe” $INSTDIR/logo1.ico
Error: “Your GStreamer installation is missing a plug-in.”
sudo apt-get update
sudo apt-get install gstreamer0.10-ffmpeg
sudo apt-get install gstreamer0.10-plugins-ugly
QT += sql
db.setDatabaseName(“E:/ShengLi/examples/qt_16110/04-day/sqlite3/my.db”); // 指定要打开的数据库名称
if(!db.open())
{
QMessageBox::critical(this,tr(“打开数据库失败”),tr(“打开my.db 错误”) );
}
QSqlQuery query;
query.prepare(“create table user(id text primary key,passwd text,name text);”);
if (! query.exec())
{
QMessageBox::warning(NULL, “my.db”,
tr(“create table error”));
}