简单问题,只为送分阿,关于timer,string,和edit ctrl

azlza 2003-10-18 09:59:00
我在一个单文档结构的程序,它每隔一定时间会更新里面的内容。我用了个比较笨的办法,把editctrl里面的值全部赋一次,然后再选最后一行。但是跑的时间长了会死机。死的时候出错在gbltext.GetLength();里。这是什么问题阿?我没看出来。那个gbltext有600K-900K大

void CViewerView::OnTimer(UINT nIDEvent)
{
if (nIDEvent==WM_USER+234)
{
if (IsChangeText)
{
CEdit& editctrl=this->GetEditCtrl();
editctrl.SetWindowText(gbltext);
int length=gbltext.GetLength();
editctrl.SetSel(length,length);
IsChangeText=0;
}
}
}
...全文
74 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
triout 2003-10-18
  • 打赏
  • 举报
回复
CEdit控件有很多方法,你可以使用:
1——
通过APPENDTEXT给EDIT追加数据
2——
把EDIT滚动到最后一行
3——
选择最后一行
poweruser 2003-10-18
  • 打赏
  • 举报
回复
gbltext是什么类型的,CString吗
CString的是有长度限制的,但具体数字忘了,你试试吧
心平至和 2003-10-18
  • 打赏
  • 举报
回复
程序像是没有错误,可能错在gbltext上,值太大了。你应看看gbltext是超出了范围。
azlza 2003-10-18
  • 打赏
  • 举报
回复
主要是数据多了,我要把老的给删除,所以,我一次赋值,这样比较简单方便
一、Qt Creator 的安装和hello world 程序的编写(原创) 1.首先到Qt 的官方网站上下载Qt Creator,这里我们下载windows 版的。 下载地址:http://qt.nokia.com/downloads 如下图我们下载:Download Qt SDK for Windows* (178Mb) 下载完成后,直接安装即可,安装过程中按默认设置即可。 2.运行Qt Creator,首先弹出的是欢迎界面,这里可以打开其自带的各种演示 程序。 3.我们用File->New 菜单来新建工程。 4.这里我们选择Qt4 Gui Application。 5.下面输入工程名和要保存到的文件夹路径。我们这里的工程名为helloworld。 6.这时软件自动添加基本的头文件,因为这个程序我们不需要其他的功能,所以 直接点击Next。 7.我们将base class 选为QDialog 对话框类。然后点击Next。 8.点击Finish,完成工程的建立。 9.我们可以看见工程中的所有文件都出现在列表中了。我们可以直接按下下面的 绿色的run 按钮或者按下Ctrl+R 快捷键运行程序。 10.程序运行会出现空白的对话框,如下图。 11.我们双击文件列表的dialog.ui 文件,便出现了下面所示的图形界面编辑界 面。 12.我们在右边的器件栏里找到Label 标签器件 13.按着鼠标左键将其拖到设计窗口上,如下图。 14.我们双击它,并将其内容改为helloworld。 15.我们在右下角的属性栏里将字体大小由9 改为15。 16.我们拖动标签一角的蓝点,将全部文字显示出来。 17.再次按下运行按钮,便会出现helloworld。 到这里helloworld 程序便完成了。 Qt Creator 编译的程序,在其工程文件夹下会有一个debug 文件夹,其中有程序的.exe 可执行文件。但Qt Creator 默认是用动态链接的, 就是可执行程序在运行时需要相应的.dll 文件。我们点击生成的.exe 文件,首 先可能显示“没有找到mingwm10.dll,因此这个应用程序未能启动。重新安装 应用程序可能会修复此问题。”表示缺少mingwm10.dll 文件。 解决这个问题我们可以将相应的.dll 文件放到系统 中。在Qt Creator 的安装目录的qt 文件下的bin 文件夹下(我安装在了D 盘, 所以路径是D:\Qt\2009.04\qt\bin),可以找到所有的相关.dll 文件。在这里 找到mingwm10.dll 文件,将其复制到C:\WINDOWS\system 文件夹下,即可。下 面再提示缺少什么dll 文件,都像这样解决就可以了。 二、Qt Creator 编写多窗口程序(原创) 实现功能: 程序开始出现一个对话框,按下按钮后便能进入主窗口,如果直 接关闭这个对话框,便不能进入主窗口,整个程序也将退出。当进入主窗口后, 我们按下按钮,会弹出一个对话框,无论如何关闭这个对话框,都会回到主窗口。 实现原理: 程序里我们先建立一个主工程,作为主界面,然后再建立一个对 话框类,将其加入工程中,然后在程序中调用自己新建的对话框类来实现多窗口。 实现过程: 1.首先新建Qt4 Gui Application 工程,工程名为nGui,Base class 选为QWidget。 建立好后工程文件列表如下图。 2.新建对话框类,如下图,在新建中,选择Qt Designer Form Class。 3.选择Dialog without Buttons。 4.类名设为myDlg。 5.点击Finish 完成。注意这里已经默认将其加入到了我们刚建的工程中了。 6.如下图,在mydlg.ui 中拖入一个Push Button,将其上的文本改为“进入主 窗口”,在其属性窗口中将其objectName 改为enterBtn,在下面的Signals and slots editor 中进行信号和槽的关联,其中,Sender 设为enterBtn,Signal 设为clicked(),Receive 设为myDlg,Slot 设为accept()。这样就实现了单击 这个按钮使这个对话框关闭并发出Accepted 信号的功能。下面我们将利用这个 信号。 7.修改主函数main.cpp,如下: #include #include "widget.h" #include "mydlg.h" //加入头文件 int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; myDlg my1; //建立自己新建的类的对象my1 if(my1.exec()==QDialog::Accepted) //利用Accepted 信号判 断enterBtn 是否被按下 { w.show(); //如果被按下,显示主窗口 return a.exec(); //程序一直执行,直到主窗口 关闭 } else return 0; //如果没被按下,则不会进入主窗口,整个程 序结束运行 } 主函数必须这么写,才能完成所要的功能。 如果主函数写成下面这样: #include #include "widget.h" #include "mydlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); myDlg my1; if(my1.exec()==QDialog::Accepted) { Widget w; w.show(); } return a.exec(); } 这样,因为w 是在if 语句里定义的,所以当if 语句执行完后它就无效了。这样 导致的后果就是,按下enterBtn 后,主界面窗口一闪就没了。如果此时对程序 改动了,再次点击运行时,就会出现error: collect2: ld returned 1 exit status 的错误。这是因为虽然主窗口没有显示,但它只是隐藏了,程序并没有 结束,而是在后台运行。所以这时改动程序,再运行时便会出错。你可以按下调 试栏上面的红色Stop 停止按钮来停止程序运行。你也可以在windows 任务管理 器的进程中将该进程结束,而后再次运行就没问题了,当然先关闭Qt Creator, 而后再重新打开,这样也能解决问题。 如果把程序改为这样: #include #include "widget.h" #include "mydlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); myDlg my1; Widget w; if(my1.exec()==QDialog::Accepted) { w.show(); } return a.exec(); } 这样虽然解决了上面主窗口一闪而过的问题,但是,如果在my1 对话框出现的时 候不点enterBtn,而是直接关闭对话框,那么此时整个程序应该结束执行,但 是事实是这样的吗?如果你此时对程序进行了改动,再次按下run 按钮,你会发 现又出现了error: collect2: ld returned 1 exit status 的错误,这说明程 序并没有结束,我们可以打开windows 任务管理器,可以看到我们的程序仍在执 行。 因为return a.exec();一句表示只要主窗口界面不退出,那么程 序就会一直执行。所以只有用第一种方法,将该语句也放到if 语句中,而在else 语句中用else return 0; ,这样如果enterBtn 没有被按下,那么程序就会结 束执行了。 到这里,我们就实现了一个界面结束执行,然后弹出另一个 界面的程序。下面我们在主窗口上加一个按钮,按下该按钮,弹出一个对话框, 但这个对话框关闭,不会使主窗口关闭。 8.如下图,在主窗口加入按钮,显示文本为“弹出一个对话框”,在其上点击鼠 标右键,在弹出的菜单中选择go to slot。 9.我们选择单击事件clicked()。 10.我们在弹出的槽函数中添加一句: my2.show(); my2 为我们新建对话框类的另一个对象,但是my2 我们还没有定义,所以 在widget.h 文件中添加相应代码,如下,先加入头文件,再加入my2 的定义语 句,这里我们将其放到private 里,因为一般的函数都放在public 里,而变量 都放在private 里。 #ifndef WIDGET_H #define WIDGET_H #include #include "mydlg.h" //包含头文件 namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); private: Ui::Widget *ui; myDlg my2; //对my2 进行定义 private slots: void on_pushButton_clicked(); }; #endif // WIDGET_H 到这里,再运行程序,便能完成我们实验要求的功能了。整个程序里,我们用两 种方法实现了信号和槽函数的关联,第一个按钮我们直接在设计器中实现其关 联;第二个按钮我们自己写了槽函数语句,其实图形的设计与直接写代码效果是 一样的。 这个程序里我们实现了两类窗口打开的方式,一个是自身消失而 后打开另一个窗口,一个是打开另一个窗口而自身不消失。可以看到他们实现的 方法是不同的。 三、Qt Creator 登录对话框(原创) 实现功能: 在弹出对话框中填写用户名和密码,按下登录按钮,如果用户名和密码均正确则 进入主窗口,如果有错则弹出警告对话框。 实现原理: 通过上节的多窗口原理实现由登录对话框进入主窗口,而用户名和密码可以用 if 语句进行判断。 实现过程: 1.先新建Qt4 Gui Application 工程,工程名为mainWidget,选用QWidget 作 为Base class,这样便建立了主窗口。文件列表如下: 2.然后新建一个Qt Designer Form Class 类,类名为loginDlg,选用Dialog without Buttons,将其加入上面的工程中。文件列表如下: 3.在logindlg.ui 中设计下面的界面:行输入框为Line Edit。其中用户名后面 的输入框在属性中设置其object Name 为usrLineEdit,密码后面的输入框为 pwdLineEdit,登录按钮为loginBtn,退出按钮为exitBtn。 4.将exitBtn 的单击后效果设为退出程序,关联如下: 5.右击登录按钮选择go to slot,再选择clicked(),然后进入其单击事件的槽 函数,写入一句 void loginDlg::on_loginBtn_clicked() { accept(); } 6.改写main.cpp: #include #include "widget.h" #include "logindlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; loginDlg login; if(login.exec()==QDialog::Accepted) { w.show(); return a.exec(); } else return 0; } 7.这时执行程序,可实现按下登录按钮进入主窗口,按下退出按钮退出程序。 8.添加用户名密码判断功能。将登陆按钮的槽函数改为: void loginDlg::on_loginBtn_clicked() { if(m_ui->usrLineEdit->text()==tr("qt")&&m_ui->pwdLineEdit->text()==tr ("123456")) //判断用户名和密码是否正确 accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); //如果不正确,弹出警告对话框 } } 并在logindlg.cpp 中加入#include 的头文件。如果不加这个头文件, QMessageBox 类不可用。 9.这时再执行程序,输入用户名为qt,密码为123456,按登录按钮便能进入主 窗口了,如果输入错了,就会弹出警告对话框。 如果输入错误,便会弹出警告提示框: 10.在logindlg.cpp 的loginDlg 类构造函数里,添上初始化语句,使密码显示 为小黑点。 loginDlg::loginDlg(QWidget *parent) : QDialog(parent), m_ui(new Ui::loginDlg) { m_ui->setupUi(this); m_ui->pwdLineEdit->setEchoMode(QLineEdit::Password); } 效果如下: 11.如果输入如下图中的用户名,在用户名前不小心加上了一些空格,结果程序 按错误的用户名对待了。 我们可以更改if 判断语句,使这样的输入也算正确。 void loginDlg::on_loginBtn_clicked() { if(m_ui->usrLineEdit->text().trimmed()==tr("qt")&&m_ui->pwdLineEdit-> text()==tr("123456")) accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); } } 加入的这个函数的作用就是移除字符串开头和结尾的空白字符。 12.最后,如果输入错误了,重新回到登录对话框时,我们希望可以使用户名和 密码框清空并且光标自动跳转到用户名输入框,最终的登录按钮的单击事件的槽 函数如下: void loginDlg::on_loginBtn_clicked() { if(m_ui->usrLineEdit->text().trimmed()==tr("qt")&&m_ui->pwdLineEdit-> text()==tr("123456")) //判断用户名和密码是否正确 accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); //如果不正确,弹出警告对话框 m_ui->usrLineEdit->clear();//清空用户名输入框 m_ui->pwdLineEdit->clear();//清空密码输入框 m_ui->usrLineEdit->setFocus();//将光标转到用户名输入框 } } 四、Qt Creator 添加菜单图标(原创) 在下面的几节,我们讲述Qt 的MainWindow 主窗口部件。这一节只讲述怎样在其 上的菜单栏里添加菜单和图标。 1.新建Qt4 Gui Application 工程,将工程命名为MainWindow,其他选项默认 即可。 生成的窗口界面如下图。其中最上面的为菜单栏。 2.我们在Type Here 那里双击,并输入“文件(&F)”,这样便可将其文件菜单的 快捷键设为Alt+F。(注意括号最好用英文半角输入,这样看着美观) 3.输入完按下Enter 键确认即可,然后在子菜单中加入“新建(&N)”,确定后, 效果如下图。 4.我们在下面的动作编辑窗口可以看到新加的“新建”菜单。 5.双击这一条,可打开它的编辑对话框。我们看到Icon 项,这里可以更改“新 建”菜单的图标。 6.我们点击后面的...号,进入资源选择器,但现在这里面是空的。所以下面我 们需要给该工程添加外部资源。 7.添加资源有两种方法。一种是直接添加系统提供的资源文件,然后选择所需图 标。另一种是自己写资源文件。我们主要介绍第一种。新建Qt Resources file, 将它命名为menu。其他默认。 8.添加完后如下图。可以看到添加的文件为menu.qrc。 9.我们最好先在工程文件夹里新建一个文件夹,如images,然后将需要的图标 文件放到其中。 10.在Qt Creator 的menu.qrc 文件中,我们点击Add 下拉框,选择Add Prefix。 我们可以将生成的/new/prefix 前缀改为其他名字,如/File。 11.然后再选择Add 下拉框,选择Add Files。再弹出的对话框中,我们到新建 的images 文件夹下,将里面的图标文件全部添加过来。 12.添加完成后,我们在Qt Creator 的File 菜单里选择Save All 选项,保存所 做的更改。 13.这时再打开资源选择器,可以看到我们的图标都在这里了。(注意:如果不显 示,可以按一下上面的Reload 按钮) 14.我们将new.png 作为“新建”菜单的图标,然后点击Shortcut,并按下 Crtl+N,便能将Crtl+N 作为“新建”菜单的快捷键。 15.这时打开文件菜单,可以看到“新建”菜单已经有图标了。 运行程序后效果如下。 16.我们在工程文件夹下查看建立的menu.qrc 文件,可以用写字板将它打开。 其具体内容如下。 附:第二种添加资源文件的方法。 1.首先右击工程文件夹,在弹出的菜单中选择Add New,添加新文件。也可以用 File 中的添加新文件。 2.我们选择文本文件。 3.将文件名设置为menu.qrc。 4.添加好文件后将其内容修改如下。可以看到就是用第一种方法生成的 menu.qrc 文件的内容。 5.保存文件后,在资源管理器中可以看到添加的图标文件。 五、Qt Creator 布局管理器的使用(原创) 上篇讲解了如何在Qt Creator 中添加资源文件,并且为菜单添加了图标。这次 我们先对那个界面进行一些完善,然后讲解一些布局管理器的知识。 首先对菜单进行完善。 1.我们在上一次的基础上再加入一些常用菜单。 “文件”的子菜单如下图。中间的分割线可以点击Add Separator 添加。 “编辑”子菜单的内容如下。 “帮助”子菜单的内容如下。 2.我们在动作编辑器中对各个菜单的属性进行设置。 如下图。 3.我们拖动“新建”菜单的图标,将其放到工具栏里。 拖动“新建”菜单的图标。 将其放到菜单栏下面的工具栏里。 4.我们再添加其他几个图标。使用Append Separator 可以添加分割线。 5.最终效果如下。如果需要删除图标,可以在图标上点击右键选择Remove action 即可。 下面简述一下布局管理器。 (这里主要以垂直布局管理器进行讲解,其他类型管理器用法与之相同,其效 果可自己验证。) 1.在左边的器件栏里拖入三个PushButton 和一个Vertical Layout(垂直布局 管理器)到中心面板。如下图。 2.将这三个按钮放入垂直布局管理器,效果如下。可以看到按钮垂直方向排列, 并且宽度可以改变,但高度没有改变。 3.我们将布局管理器整体选中,按下上面工具栏的Break Layout 按钮,便可取 消布局管理器。(我们当然也可以先将按钮移出,再按下Delete 键将布局管理 器删除。) 4.下面我们改用分裂器部件(QSplitter)。 先将三个按钮同时选中,再按下上面工具栏的Lay Out Vertically in Splitter (垂直分裂器)。 效果如下图。可以看到按钮的大小可以随之改动。这也就是分裂器和布局管理器 的分别。 5.其实布局管理器不但能控制器件的布局,还有个很重要的用途是,它能使器件 的大小随着窗口大小的改变而改变。 我们先在主窗口的中心拖入一个文本编辑器Text Edit。 这时直接运行程序,效果如下。可以看到它的大小和位置不会随着窗口改变。 下面我们选中主窗口部件,然后在空白处点击鼠标右键,选择Layout->Lay Out in a Grid,使整个主窗口的中心区处于网格布局管理器中。 可以看到,这时文本编辑器已经占据了整个主窗口的中心区。 运行一下程序,可以看到无论怎样拉伸窗口,文本编辑框的大小都会随之改变。 我们在这里一共讲述了三种使用布局管理器的方法,一种是去器件栏添加,一 种是用工具栏的快捷图标,还有一种是使用鼠标右键的选项。 程序中用到的图标是我从Ubuntu 中复制的,可以到 http://www.qtcn.org/bbs/read.php?tid=23252&page=1&toread=1 下载到。 六、Qt Creator 实现文本编辑(原创) 前面已经将界面做好了,这里我们为其添加代码,实现文本编辑的功能。 首先实现新建文件,文件保存,和文件另存为的功能。 (我们先将上次的工程文件夹进行备份,然后再对其进行修改。在写较大的程序 时,经常对源文件进行备份,是个很好的习惯。) 在开始正式写程序之前,我们先要考虑一下整个流程。因为我们要写记事本一 样的软件,所以最好先打开windows 中的记事本,进行一些简单的操作,然后 考虑怎样去实现这些功能。再者,再强大的软件,它的功能也是一个一个加上 去的,不要设想一下子写出所有的功能。我们这里先实现新建文件,保存文件, 和文件另存为三个功能,是因为它们联系很紧,而且这三个功能总的代码量也 不是很大。 因为三个功能之间的关系并不复杂,所以我们这里便不再画流程图,而只是简 单描述一下。 新建文件,那么如果有正在编辑的文件,是否需要保存呢? 如果需要进行保存,那这个文件以前保存过吗?如果没有保存过,就应该先将其 另存为。 下面开始按这些关系写程序。 1.打开Qt Creator,在File 菜单中选择Open,然后在工程文件夹中打开 MainWindow.pro 工程文件。 先在main.cpp 文件中加入以下语句,让程序中可以使用中文。 在其中加入#include 头文件包含,再在主函数中加入下面一行: QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 这样在程序中使用中文,便能在运行时显示出来了。更改后文件如下图。 2.在mainwindow.h 文件中的private 下加入以下语句。 bool isSaved; //为true 时标志文件已经保存,为false 时标志文件尚未保存 QString curFile; //保存当前文件的文件名 void do_file_New(); //新建文件 void do_file_SaveOrNot(); //修改过的文件是否保存 void do_file_Save(); //保存文件 void do_file_SaveAs(); //文件另存为 bool saveFile(const QString& fileName); //存储文件 这些是变量和函数的声明。其中isSaved 变量起到标志的作用,用它来标志文件 是否被保存过。然后我们再在相应的源文件里进行这些函数的定义。 3.在mainwindow.cpp 中先加入头文件#include ,然后在构造函数里添 加以下几行代码。 isSaved = false; //初始化文件为未保存过状态 curFile = tr("未命名.txt"); //初始化文件名为“未命名.txt” setWindowTitle(curFile); //初始化主窗口的标题 这是对主窗口进行初始化。效果如下。 4.然后添加“新建”操作的函数定义。 void MainWindow::do_file_New() //实现新建文件的功能 { do_file_SaveOrNot(); isSaved = false; curFile = tr("未命名.txt"); setWindowTitle(curFile); ui->textEdit->clear(); //清空文本编辑器 ui->textEdit->setVisible(true); //文本编辑器可见 } 新建文件,先要判断正在编辑的文件是否需要保存。然后将新建的文件标志为未 保存过状态。 5.再添加do_file_SaveOrNot 函数的定义。 void MainWindow::do_file_SaveOrNot() //弹出是否保存文件对话框 { if(ui->textEdit->document()->isModified()) //如果文件被更改过,弹出保 存对话框 { QMessageBox box; box.setWindowTitle(tr("警告")); box.setIcon(QMessageBox::Warning); box.setText(curFile + tr(" 尚未保存,是否保存?")); box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); if(box.exec() == QMessageBox::Yes) //如果选择保存文件,则执行保存操作 do_file_Save(); } } 这个函数实现弹出一个对话框,询问是否保存正在编辑的文件。 6.再添加“保存”操作的函数定义。 void MainWindow::do_file_Save() //保存文件 { if(isSaved){ //如果文件已经被保存过,直接保存文件 saveFile(curFile); } else{ do_file_SaveAs(); //如果文件是第一次保存,那么调用另存为 } } 对文件进行保存时,先判断其是否已经被保存过,如果没有被保存过,就要先对 其进行另存为操作。 7.下面是“另存为”操作的函数定义。 void MainWindow::do_file_SaveAs() //文件另存为 { QString fileName = QFileDialog::getSaveFileName(this,tr("另存为 "),curFile); //获得文件名 if(!fileName.isEmpty()) //如果文件名不为空,则保存文件内容 { saveFile(fileName); } } 这里弹出一个文件对话框,显示文件另存为的路径。 8.下面是实际文件存储操作的函数定义。 bool MainWindow::saveFile(const QString& fileName) //保存文件内容,因为可能保存失败,所以具有返回值,来表明是否保存成功 { QFile file(fileName); if(!file.open(QFile::WriteOnly | QFile::Text)) //以只写方式打开文件,如果打开失败则弹出提示框并返回 { QMessageBox::warning(this,tr("保存文件"), tr("无法保存文件 %1:\n %2").arg(fileName) .arg(file.errorString())); return false; } //%1,%2 表示后面的两个arg 参数的值 QTextStream out(&file); //新建流对象,指向选定的文件 out << ui->textEdit->toPlainText(); //将文本编辑器里的内容以纯文本 的形式输出到流对象中 isSaved = true; curFile = QFileInfo(fileName).canonicalFilePath(); //获得文件的标准路 径 setWindowTitle(curFile); //将窗口名称改为现在窗口的路径 return true; } 这个函数实现将文本文件进行存储。下面我们对其中的一些代码进行讲解。 QFile file(fileName);一句,定义了一个QFile 类的对象file,其中filename 表明这个文件就是我们保存的的文件。然后我们就可以用file 代替这个文件, 来进行一些操作。Qt 中文件的操作和C,C++很相似。对于QFile 类对象怎么使 用,我们可以查看帮助。 点击Qt Creator 最左侧的Help,在其中输入QFile, 在搜索到的列表中选择QFile 即可。这时在右侧会显示出QFile 类中所有相关信 息以及他们的用法和说明。 // 我们往下拉,会发现下面有关于怎么读取文件的示例代码。 // // 再往下便能看到用QTextStream 类对象,进行字符串输入的例子。下面也提到了 QFileInfo 和QDir 等相关的类,我们可以点击它们去看一下具体的使用说明。 // 上面只是做了一个简单的说明。以后我们对自己不明白的类都可以去帮助里进行 查找,这也许是我们以后要做的最多的一件事了。对于其中的英文解释,我们最 好想办法弄明白它的大意,其实网上也有一些中文的翻译,但最好还是从一开始 就尝试着看英文原版的帮助,这样以后才不会对中文翻译产生依赖。 我们这次只是很简单的说明了一下怎样使用帮助文件,这不表明 它不重要,而是因为这里不可能将每个类的帮助都解释一遍,没有那么多时间, 也没有那么大的篇幅。而更重要的是因为,我们这个教程只是引你入门,所以很 多东西需要自己去尝试。 在以后的教程里,如果不是特殊情况,就不会再对其中的类进行 详细解释,文章中的重点是对整个程序的描述,其中不明白的类,自己查看帮助。 9.双击mainwindow.ui 文件,在图形界面窗口下面的Action Editor 动作编辑 器里,我们右击“新建”菜单一条,选择Go to slot,然后选择triggered(), 进入其触发事件槽函数。 同理,进入其他两个菜单的槽函数,将相应的操作的函数写入槽函数中。如下。 void MainWindow::on_action_New_triggered() //信号和槽的关联 { do_file_New(); } void MainWindow::on_action_Save_triggered() { do_file_Save(); } void MainWindow::on_action_SaveAs_triggered() { do_file_SaveAs(); } 这时点击运行,就能够实现新建文件,保存文件,文件另存为的功能了。 然后实现打开,关闭,退出,撤销,复制,剪切,粘贴的功能。 先备份上次的工程文件,然后再将其打开。 1.先在mainwindow.h 文件中加入函数的声明。 void do_file_Open(); //打开文件 bool do_file_Load(const QString& fileName); //读取文件 2.再在mainwindow.cpp 文件中写函数的功能实现。 void MainWindow::do_file_Open()//打开文件 { do_file_SaveOrNot();//是否需要保存现有文件 QString fileName = QFileDialog::getOpenFileName(this); //获得要打开的文件的名字 if(!fileName.isEmpty())//如果文件名不为空 { do_file_Load(fileName); } ui->textEdit->setVisible(true);//文本编辑器可见 } bool MainWindow::do_file_Load(const QString& fileName) //读取文件 { QFile file(fileName); if(!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this,tr("读取文件"),tr("无法读取文件 %1:\n%2.").arg(fileName).arg(file.errorString())); return false; //如果打开文件失败,弹出对话框,并返回 } QTextStream in(&file); ui->textEdit->setText(in.readAll()); //将文件中的所有内容都 写到文本编辑器中 curFile = QFileInfo(fileName).canonicalFilePath(); setWindowTitle(curFile); return true; } 上面的打开文件函数与文件另存为函数相似,读取文件的函数与文件存储函数相 似。 3.然后按顺序加入更菜单的关联函数,如下。 void MainWindow::on_action_Open_triggered() //打开操作 { do_file_Open(); } // void MainWindow::on_action_Close_triggered() //关闭操作 { do_file_SaveOrNot(); ui->textEdit->setVisible(false); } // void MainWindow::on_action_Quit_triggered() //退出操作 { on_action_Close_triggered(); //先执行关闭操作 qApp->quit(); //再退出系统,qApp 是指向应用程序的全局指针 } // void MainWindow::on_action_Undo_triggered() //撤销操作 { ui->textEdit->undo(); } // void MainWindow::on_action_Cut_triggered() //剪切操作 { ui->textEdit->cut(); } // void MainWindow::on_action_Copy_triggered() //复制操作 { ui->textEdit->copy(); } // void MainWindow::on_action_Past_triggered() //粘贴操作 { ui->textEdit->paste(); } 因为复制,撤销,全选,粘贴,剪切等功能,是TextEdit 默认就有的,所以我 们只需调用一下相应函数就行。 到这里,除了查找和帮助两个菜单的功能没有加上以外,其他功能都已经实现了。 七、Qt Creator 实现文本查找(原创) 现在加上查找菜单的功能。因为这里要涉及关于Qt Creator 的很多实用功能, 所以单独用一篇文章来介绍。 以前都用设计器设计界面,而这次我们用代码实现一个简单的查找对话框。对于 怎么实现查找功能的,我们详细地分步说明了怎么进行类中方法的查找和使用。 其中也将Qt Creator 智能化的代码补全功能和程序中函数的声明位置和定义位 置间的快速切换进行了介绍。 1.首先还是保存以前的工程,然后再将其打开。 我们发现Qt Creator 默认的字体有点小,可以按下Ctrl 键的同时按两下+键, 来放大字体。也可以选择Edit->Advanced->Increase Font Size。 2.在mainwindow.h 中加入#include Edit>的头文件包含,在private 中 添加 QLineEdit *find_textLineEdit; //声明一个行编辑器,用于输入要查找的内容 在private slots 中添加 void show_findText(); 在该函数中实现查找字符串的功能。 3.我们进入查找菜单的触发事件槽函数,更改如下。 void MainWindow::on_action_Find_triggered() { QDialog *findDlg = new QDialog(this); //新建一个对话框,用于查找操作,this 表明它的父窗口是MainWindow。 findDlg->setWindowTitle(tr("查找")); //设置对话框的标题 find_textLineEdit = new QLineEdit(findDlg); //将行编辑器加入到新建的查找对话框中 QPushButton *find_Btn = new QPushButton(tr("查找下一个"),findDlg); //加入一个“查找下一个”的按钮 QVBoxLayout* layout = new QVBoxLayout(findDlg); layout->addWidget(find_textLineEdit); layout->addWidget(find_Btn); //新建一个垂直布局管理器,并将行编辑器和按钮加入其中 findDlg ->show(); //显示对话框 connect(find_Btn,SIGNAL(clicked()),this,SLOT(show_findText())); //设置“查找下一个”按钮的单击事件和其槽函数的关联 } 这里我们直接用代码生成了一个对话框,其中一个行编辑器可以输入要查找的字 符,一个按钮可以进行查找操作。我们将这两个部件放到了一个垂直布局管理器 中。然后显示这个对话框。并设置了那个按钮单击事件与show_findText()函数 的关联。 5.下面我们开始写实现查找功能的show_findText()函数。 void MainWindow::show_findText()//“查找下一个”按钮的槽函数 { QString findText = find_textLineEdit->text(); //获取行编辑器中的内容 } 先用一个QString 类的对象获得要查找的字符。然后我们一步一步写查找操作的 语句。 6.在下一行写下ui,然后直接按下键盘上的“<.”键,这时系统会根据是否是 指针对象而自动生成“->”或“.”,因为ui 是指针对象,所以自动生成“->” 号,而且弹出了ui 中的所有部件名称的列表。如下图。 7.我们用向下的方向键选中列表中的textEdit。或者我们可以先输入text,这 时能缩减列表的内容。 8.如上图我们将鼠标放到textEdit 上,这时便出现了textEdit 的类名信息, 且后面出现一个F1 按键。我们按下键盘上的F1,便能出现textEdit 的帮助。 9.我们在帮助中向下拉,会发现这里有一个find 函数。 10.我们点击find,查看其详细说明。 11.可以看到find 函数可以实现文本编辑器中字符串的查找。其中有一个 FindFlags 的参数,我们点击它查看其说明。 12.可以看到它是一个枚举变量(enum),有三个选项,第一项是向后查找(即 查找光标以前的内容,这里的前后是相对的说法,比如第一行已经用完了,光 标在第二行时,把第一行叫做向后。),第二项是区分大小写查找,第三项是 查找全部。 13.我们选用第一项,然后写出下面的语句。 ui->textEdit->find(findText,QTextDocument::FindBackward); //将行编辑器中的内容在文本编辑器中进行查找 当我们刚打出“f”时,就能自动弹出textEdit 类的相关属性和方法。 可以看到,当写完函数名和第一个“(”后,系统会自动显示出该函数的函数原 型,这样可以使我们减少出错。 14.这时已经能实现查找的功能了。但是我们刚才看到find 的返回值类型是bool 型,而且,我们也应该为查找不到字符串作出提示。 if(!ui->textEdit->find(findText,QTextDocument::FindBackward)) { QMessageBox::warning(this,tr("查找"),tr("找不到 %1") .arg(findText); } 因为查找失败返回值是false,所以if 条件加了“!”号。在找不到时弹出警 告对话框。 15.到这里,查找功能就基本上写完了。show_findText()函数的内容如下。 我们会发现随着程序功能的增强,其中的函数也会越来越多,我们都会为查找 某个函数的定义位置感到头疼。而在Qt Creator 中有几种快速定位函数的方法, 我们这里讲解三种。 第一,在函数声明的地方直接跳转到函数定义的地方。 如在do_file_Load 上点击鼠标右键,在弹出的菜单中选择Follow Symbol under Cursor 或者下面的Switch between Method Declaration/Definition。 这时系统就会自动跳转到函数定义的位置。如下图。 第二,快速查找一个文件里的所有函数。 我们可以点击窗口最上面的下拉框,这里会显示本文件中所有函数的列表。 第三,利用查找功能。 1.我们先将鼠标定位到一个函数名上。 2.然后选择Edit->Find/Replace->Find Dialog。 3.这时会出现一个查找对话框,可以看到要查找的函数名已经写在里面了。 4.当我们按下Search 按钮后,会在查找结果窗口显示查找到的结果。 5.我们点击第二个文件。会发现在这个文件中有两处关键字是高亮显示。 6.我们双击第二项,就会自动跳转到函数的定义处。 文章讲到这里,我们已经很详细地说明了怎样去使用一个类里面没有用过的方法 函数;也说明了Qt Creator 中的一些便捷操作。可以看到,Qt Creator 开发环 境,有很多很人性化的设计,我们应该熟练应用它们。 在以后的文章中,我们不会再很详细地去用帮助来说明一个函数是 怎么来的,该怎么用,这些应该自己试着去查找。 八、Qt Creator 实现状态栏显示(原创) 在程序主窗口Mainwindow 中,有菜单栏,工具栏,中心部件和状态栏。前面几 个已经讲过了,这次讲解状态栏的使用。 程序中有哪些不明白的类或函数,请自己查看帮助。 1.我们在mainwindow.h 中做一下更改。 加入头文件包含: #include 加入私有变量和函数: QLabel* first_statusLabel; //声明两个标签对象,用于显示状态信息 QLabel* second_statusLabel; void init_statusBar(); //初始化状态栏 加入一个槽函数声明:void do_cursorChanged(); //获取光标位置信息 2.在mainwindow.cpp 中加入状态栏初始化函数的定义。 void MainWindow::init_statusBar() { QStatusBar* bar = ui->statusBar; //获取状态栏 first_statusLabel = new QLabel; //新建标签 first_statusLabel->setMinimumSize(150,20); //设置标签最小尺寸 first_statusLabel->setFrameShape(QFrame::WinPanel); //设置标签形状 first_statusLabel->setFrameShadow(QFrame::Sunken); //设置标签阴影 second_statusLabel = new QLabel; second_statusLabel->setMinimumSize(150,20); second_statusLabel->setFrameShape(QFrame::WinPanel); second_statusLabel->setFrameShadow(QFrame::Sunken); bar->addWidget(first_statusLabel); bar->addWidget(second_statusLabel); first_statusLabel->setText(tr("欢迎使用文本编辑器")); //初始化内容 second_statusLabel->setText(tr("yafeilinux 制作!")); } 这里将两个标签对象加入到了主窗口的状态栏里,并设置了他们的外观和初值。 3.在构造函数里调用状态栏初始化函数。 init_statusBar(); 这时运行程序,效果如下。 4.在mainwindow.cpp 中加入获取光标位置的函数的定义。 void MainWindow::do_cursorChanged() { int rowNum = ui->textEdit->document()->blockCount(); //获取光标所在行的行号 const QTextCursor cursor = ui->textEdit->textCursor(); int colNum = cursor.columnNumber(); //获取光标所在列的列号 first_statusLabel->setText(tr("%1 行 %2 列").arg(rowNum).arg(colNum)); //在状态栏显示光标位置 } 这个函数可获取文本编辑框中光标的位置,并显示在状态栏中。 5.在构造函数添加光标位置改变信号的关联。 connect(ui->textEdit,SIGNAL(cursorPositionChanged()),this,SLOT(do_cur sorChanged())); 这时运行程序。效果如下。 6.在do_file_Load 函数的最后添加下面语句。 second_statusLabel->setText(tr("打开文件成功")); 7.在saveFile 函数的最后添加以下语句。 second_statusLabel->setText(tr("保存文件成功")); 8.在on_action_Find_triggered 函数的后面添加如下语句。 second_statusLabel->setText(tr("正在进行查找")); 9.在on_action_Close_triggered 函数最后添加如下语句。 first_statusLabel->setText(tr("文本编辑器已关闭")); second_statusLabel->setText(tr("yafeilinux 制作!")); 到这里整个文本编辑器的程序就算写完了。我们这里没有写帮助菜单的功能实 现,大家可以自己添加。而且程序中也有很多漏洞和不完善的地方,如果有兴 趣,大家也可以自己修改。因为时间和篇幅的原因,我们这里就不再过多的讲 述。 九、Qt Creator 中鼠标键盘事件的处理实现自定义鼠标指针(原创) 我们前面一直在说信号,比方说用鼠标按了一下按钮,这样就会产生一个按钮的 单击信号,然后我们可以在相应的槽函数里进行相应功能的设置。其实在按下鼠 标后,程序要先接收到鼠标按下的事件,然后将这个事件按默认的设置传给按钮。 可以看出,事件和信号并不是一回事,事件比信号更底层。而我们以前把单击按 钮也叫做事件,这是不确切的,不过大家都知道是什么意思,所以当时也没有细 分。 Qt 中的事件可以在QEvent 中查看。下面我们只是找两个例子来进行简单的演示。 1.还是先建立一个Qt4 Gui Application 工程,我这里起名为event。 2.添加代码,让程序中可以使用中文。 即在main.cpp 文件中加入#include 的头文件包含。 再在下面的主函数里添加 QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 3.在mainwindow.h 文件中做一下更改。 添加#include 头文件。因为这样就包含了QtGui 中所有的子文件。 在public 中添加两个函数的声明 void mouseMoveEvent(QMouseEvent *); void keyPressEvent(QKeyEvent *); 4.我们在mainwindow.ui 中添加一个Label 和一个PushButton,将他们拉长点, 因为一会要在上面显示标语。 5.在mainwindow.cpp 中的构造函数里添加两个部件的显示文本。 ui->label->setText(tr("按下键盘上的A 键试试!")); ui->pushButton->setText(tr("按下鼠标的一个键,然后移动鼠标试试")); 6.然后在下面进行两个函数的定义。 /*以下是鼠标移动事件*/ void MainWindow::mouseMoveEvent(QMouseEvent *m) {//这里的函数名和参数不能更改 QCursor my(QPixmap("E:/Qt/Qt-Creator-Example/event/time.png")); //为鼠标指针选择图片,注意这里要用绝对路径,且要用“/”,而不能用“\” QApplication::setOverrideCursor(my); //将鼠标指针更改为自己设置的图片 int x = m->pos().x(); int y = m->pos().y(); //获取鼠标现在的位置坐标 ui->pushButton->setText(tr("鼠标现在的坐标是(%1,%2), 哈哈好玩吧 ").arg(x).arg(y)); //将鼠标的位置坐标显示在按钮上 ui->pushButton->move(m->pos()); //让按钮跟随鼠标移动 } /*以下是键盘按下事件*/ void MainWindow::keyPressEvent(QKeyEvent *k) { if(k->key() == Qt::Key_A) //判断是否是A 键按下 { ui->label->setPixmap(QPixmap("E:/Qt/Qt-Creator-Example/event/linux.jp g")); ui->label->resize(100,100); //更改标签图片和大小 } } 注意:这两个函数不是自己新建的,而是对已有函数的重定义,所有函数名和参 数都不能改。第一个函数对鼠标移动事件进行了重写。其中实现了鼠标指针的更 改,和按钮跟随鼠标移动的功能。 第二个函数对键盘的A 键按下实现了新的功能。 效果如下。 按下鼠标的一个键,并移动鼠标。 按下键盘上的A 键。 十、Qt Creator 中实现定时器和产生随机数(原创) 有两种方法实现定时器。 第一种。自己建立关联。 1.新建Gui 工程,工程名可以设置为timer。并在主界面上添加一个标签label, 并设置其显示内容为“0000-00-00 00:00:00 星期日”。 2.在mainwindow.h 中添加槽函数声明。 private slots: void timerUpDate(); 3.在mainwindow.cpp 中添加代码。 添加#include 的头文件包含,这样就包含了QtCore 下的所有文件。 构造函数里添加代码: QTimer *timer = new QTimer(this); //新建定时器 connect(timer,SIGNAL(timeout()),this,SLOT(timerUpDate())); //关联定时器计满信号和相应的槽函数 timer->start(1000); //定时器开始计时,其中1000 表示1000ms 即1 秒 4.然后实现更新函数。 void MainWindow::timerUpDate() { QDateTime time = QDateTime::currentDateTime(); //获取系统现在的时间 QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd"); //设置系统时间显示格式 ui->label->setText(str); //在标签上显示时间 } 5.运行程序,效果如下。 第二种。使用事件。(有点像单片机中的定时器啊) 1.新建工程。在窗口上添加两个标签。 2.在main.cpp 中添加代码,实现中文显示。 #include QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 3.在mainwindow.h 中添加代码。 void timerEvent(QTimerEvent *); 4.在mainwindow.cpp 中添加代码。 添加头文件#include 在构造函数里添加以下代码。 startTimer(1000); //其返回值为1,即其timerId 为1 startTimer(5000);//其返回值为2,即其timerId 为2 startTimer(10000); //其返回值为3,即其timerId 为3 添加了三个定时器,它们的timerId 分别为1,2,3。注意,第几个定时器的返 回值就为几。所以要注意定时器顺序。 在下面添加函数实现。 void MainWindow::timerEvent(QTimerEvent *t) //定时器事件 { switch(t->timerId()) //判断定时器的句柄 { case 1 : ui->label->setText(tr("每秒产生一个随机数: %1").arg(qrand()%10));break; case 2 : ui->label_2->setText(tr("5 秒后软件将关闭"));break; case 3 : qApp->quit();break; //退出系统 } } 这里添加了三个定时器,并都在定时器事件中判断它们,然后执行相应的功能。 这样就不用每个定时器都写一个关联函数和槽函数了。 随机数的实现: 上面程序中的qrand(),可以产生随机数,qrand()%10 可以产生0-9 之间的随机 数。要想产生100 以内的随机数就%100。以此类推。 但这样每次启动程序后,都按同一种顺序产生随机数。为了实现每次启动程序产 生不同的初始值。我们可以使用qsrand(time(0));实现设置随机数的初值,而 程序每次启动时time(0)返回的值都不同,这样就实现了产生不同初始值的功 能。 我们将qsrand(time(0));一句加入构造函数里。 程序最终运行效果如下。 十一、Qt 2D 绘图(一)绘制简单图形(原创) 声明:本文原创于yafeilinux 的百度博客,http://hi.baidu.com/yafeilinux 转载请注明出处。 说明:以后使用的环境为基于Qt 4.6 的Qt Creator 1.3.0 windows 版本 本文介绍在窗口上绘制最简单的图形的方法。 1.新建Qt4 Gui Application 工程,我这里使用的工程名为painter01,选用 QDialog 作为Base class 2.在dialog.h 文件中声明重绘事件函数void paintEvent(QPaintEvent *); 3.在dialog.cpp 中添加绘图类QPainter 的头文件包含#include 4.在下面进行该函数的重定义。 void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawLine(0,0,100,100); } 其中创建了QPainter 类对象,它是用来进行绘制图形的,我们这里画了一条线 Line,其中的参数为线的起点(0,0),和终点(100,100)。这里的数值指的 是像素,详细的坐标设置我们以后再讲,这里知道(0,0)点指的是窗口的左上 角即可。运行效果如下: 5.在qt 的帮助里可以查看所有的绘制函数,而且下面还给出了相关的例子。 6.我们下面将几个知识点说明一下,帮助大家更快入门。 将函数改为如下: void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); QPen pen; //画笔 pen.setColor(QColor(255,0,0)); QBrush brush(QColor(0,255,0,125)); //画刷 painter.setPen(pen); //添加画笔 painter.setBrush(brush); //添加画刷 painter.drawRect(100,100,200,200); //绘制矩形 } 这里的pen 用来绘制边框,brush 用来进行封闭区域的填充,QColor 类用来提供 颜色,我们这里使用了rgb 方法来生成颜色,即(red,green,blue),它们取 值分别是0-255,例如(255,0,0)表示红色,而全0 表示黑色,全255 表示 白色。后面的(0,255,0,125),其中的125 是透明度(alpha)设置,其值 也是从0 到255,0 表示全透明。最后将画笔和画刷添加到painter 绘制设备中, 画出图形。这里的Rect 是长方形,其中的参数为(100,100)表示起始坐标, 200,200 表示长和宽。效果如下: 7.其实画笔和画刷也有很多设置,大家可以查看帮助。 QPainter painter(this); QPen pen(Qt::DotLine); QBrush brush(Qt::blue); brush.setStyle(Qt::HorPattern); painter.setPen(pen); painter.setBrush(brush); painter.drawRect(100,100,200,200); 这里我们设置了画笔的风格为点线,画刷的风格为并行横线,效果如下: 在帮助里可以看到所有的风格。 我们这里用了Qt::blue,Qt 自定义的几个颜色如下: 8.画弧线,这是帮助里的一个例子。 QRectF rectangle(10.0, 20.0, 80.0, 60.0); //矩形 int startAngle = 30 * 16; //起始角度 int spanAngle = 120 * 16; //跨越度数 QPainter painter(this); painter.drawArc(rectangle, startAngle, spanAngle); 这里要说明的是,画弧线时,角度被分成了十六分之一,就是说,要想为30 度, 就得是30*16。它有起始角度和跨度,还有位置矩形,要想画出自己想要的弧线, 就要有一定的几何知识了。这里就不再祥述。 十二、Qt 2D 绘图(二)渐变填充(原创) 声明:本文原创于yafeilinux 的百度博客,http://hi.baidu.com/yafeilinux 转载请注明出处。 在qt 中提供了三种渐变方式,分别是线性渐变,圆形渐变和圆锥渐变。如果能 熟练应用它们,就能设计出炫目的填充效果。 线性渐变: 1.更改函数如下: void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); QLinearGradient linearGradient(100,150,300,150); //从点(100,150)开始到点(300,150)结束,确定一条直线 linearGradient.setColorAt(0,Qt::red); linearGradient.setColorAt(0.2,Qt::black); linearGradient.setColorAt(0.4,Qt::yellow); linearGradient.setColorAt(0.6,Qt::white); linearGradient.setColorAt(0.8,Qt::green); linearGradient.setColorAt(1,Qt::blue); //将直线开始点设为0,终点设为1,然后分段设置颜色 painter.setBrush(linearGradient); painter.drawRect(100,100,200,100); //绘制矩形,线性渐变线正好在矩形的水平中心线上 } 效果如下: 圆形渐变: 1.更改函数内容如下: QRadialGradient radialGradient(200,100,100,200,100); //其中参数分别为圆形渐变的圆心(200,100),半径100,和焦点(200, 100) //这里让焦点和圆心重合,从而形成从圆心向外渐变的效果 radialGradient.setColorAt(0,Qt::black); radialGradient.setColorAt(1,Qt::yellow); //渐变从焦点向整个圆进行,焦点为起始点0,圆的边界为1 QPainter painter(this); painter.setBrush(radialGradient); painter.drawEllipse(100,0,200,200); //绘制圆,让它正好和上面的圆形渐变的圆重合 效果如下: 2.要想改变填充的效果,只需要改变焦点的位置和渐变的颜色位置即可。 改变焦点位置:QRadialGradient radialGradient(200,100,100,100,100); 效果如下: 锥形渐变: 1.更改函数内容如下: //圆锥渐变 QConicalGradient conicalGradient(50,50,0); //圆心为(50,50),开始角度为0 conicalGradient.setColorAt(0,Qt::green); conicalGradient.setColorAt(1,Qt::white); //从圆心的0 度角开始逆时针填充 QPainter painter(this); painter.setBrush(conicalGradient); painter.drawEllipse(0,0,100,100); 效果如下: 2.可以更改开始角度,来改变填充效果 QConicalGradient conicalGradient(50,50,30); 开始角度设置为30 度,效果如下: 其实三种渐变的设置都在于焦点和渐变颜色的位置,如果想设计出漂亮的渐变 效果,还要有美术功底啊! 十二、Qt 2D 绘图(三)绘制文字(原创) 声明:本文原创于yafeilinux 的百度博客,http://hi.baidu.com/yafeilinux 转载请注明出处。 接着上一次的教程,这次我们学习在窗体上绘制文字。 1.绘制最简单的文字。 我们更改重绘函数如下: void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawText(100,100,"yafeilinux"); } 我们在(100,100)的位置显示了一行文字,效果如下。 2.为了更好的控制字体的位置。我们使用另一个构造函数。在帮助里查看 drawText,如下。 这里我们看到了构造函数的原型和例子。其中的flags 参数可以控制字体在矩形 中的位置。我们更改函数内容如下。 void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); QRectF ff(100,100,300,200); //设置一个矩形 painter.drawRect(ff); //为了更直观地看到字体的位置,我们绘制出这个矩形 painter.setPen(QColor(Qt::red)); //设置画笔颜色为红色 painter.drawText(ff,Qt::AlignHCenter,"yafeilinux"); //我们这里先让字体水平居中 } 效果如下。 可以看到字符串是在最上面水平居中的。如果想让其在矩形正中间,我们可以使 用Qt::AlignCenter。 这里我们也可以使用两个枚举变量进行按位与操作,例如可以使用 Qt::AlignBottom|Qt::AlignHCenter 实现让文字显示在矩形下面的正中间。效 果如下。 对于较长的字符串,我们也可以利用“\n”进行换行,例如"yafei\nlinux"。效 果如下。 3.如果要使文字更美观,我们就需要使用QFont 类来改变字体。先在帮助中查 看一下这个类。 可以看到它有好几个枚举变量来设置字体。下面的例子我们对主要的几个选项进 行演示。 更改函数如下。 void Dialog::paintEvent(QPaintEvent *) { QFont font("Arial",20,QFont::Bold,true); //设置字体的类型,大小,加粗,斜体 font.setUnderline(true); //设置下划线 font.setOverline(true); //设置上划线 font.setCapitalization(QFont::SmallCaps); //设置大小写 font.setLetterSpacing(QFont::AbsoluteSpacing,5); //设置间距 QPainter painter(this); painter.setFont(font); //添加字体 QRectF ff(100,100,300,200); painter.drawRect(ff); painter.setPen(QColor(Qt::red)); painter.drawText(ff,Qt::AlignCenter,"yafeilinux"); } 效果如下。 这里的所有字体我们可以在设计器中进行查看。如下。 基于Qt 4.6 的Qt Creator 1.3.0 环境变量设置(原创) 如果你以前安装过visual studio 2005 之类的软件,那么装上Qt Creator 1.3.0 后,编译运行其自带的演示程序时就可能出现如下图的,105 个错误,几十个警 告的问题。 我们查看输出窗口,如下图。会发现它居然显示VC98 之类的东西,就是说它并 没有去自己的include 文件夹 中查找文件。我们可以怀疑是系统环境变量的问题了。 点击Qt Creator 界面左侧的projects 图标,查看工程信息。这里我们主要查看 编辑环境Buid Environment,点击其右侧的show Details。 可以看到其中的include 和lib 均指向了virtual studio 文件夹中,我们需要 将其改正。 将他们都改为自己Qt Creator 安装目录下的相关路径,如下图。(要换成你的 安装路径) 改完后会发现新的设置已经显示出来了。 我们查看下面的Run Environment,发现它已经自己改过来了。 回到编辑界面,右击工程文件,在弹出的菜单上选择Clean project,清空以前 的编译信息。 然后运行Run qmake,生成Makefile 文件。 最后,点击run 或者build 都可,这时程序已经能正常编译运行了。 基于Qt 4.6 的Qt Creator 1.3.0 写helloworld 程序注意事项(原创) 注意:下面指的是在windows 下,linux 下的情况可进行相应改变 昨天Qt 4.6 和Qt Creator 1.3.0 正式版发布了,但是如果以前用过旧版本,就 可能出一些问题。 1.用debug 方式 如果你以前用了Qt 4.5 的Qt Creator,并且将QtCored4.dll,QtGuid4.dll, mingwm10.dll 等文件放到了C 盘的system 文件夹下。那么请先将它们删除,不 然编译不会通过。 编译完helloworld 程序后,如果要直接执行exe 文件,需要将安装目录(新版 Qt)下的qt/bin 目录下的QtCored4.dll,QtGuid4.dll,mingwm10.dll,和 libgcc_s_dw2-1.dll(这个是新增的)文件放在exe 文件夹中。或者将它们放到 系统的system 文件夹下。 2.选择release 方式 编译程序后生成exe 文件 1.需要Qt 安装目录下的qt/bin 目录中的QtGui4.dll ,Qt Core4.dll, libgcc_s_dw2-1.dll 以及mingwm10.dll 四个文件的支持,将它们拷贝到exe 文 件目录下。 2.程序中默认只支持png 图片,如果使用了gif,jpg 等格式的文件是显示不出 来的。需要将Qt 安装目录下的qt/plugins/目录中的imageformats 文件夹拷贝 到exe 文件目录下(注意是整个文件夹)。而imageformats 文件夹中只需要保 留你需要的文件,例如你只需要支持gif 文件,就只保留qgif4.dll 即可。 ‘Qt Creator 发布release 软件相关注意事项(原创) 注意:环境是windows 选择release 编译程序后生成exe 文件 1.需要Qt 安装目录下的qt/bin 目录中的QtGui4.dll 和 Qt Core4.dll 以及 mingwm10.dll 三个文件的支持,将它们拷贝到exe 文件目录下。 2.程序中默认只支持png 图片,如果使用了gif,jpg 等格式的文件是显示不出 来的。需要将Qt 安装目录下的qt/plugins/目录中的imageformats 文件夹拷贝 到exe 文件目录下(注意是整个文件夹)。而imageformats 文件夹中只需要保 留你需要的文件,例如你只需要支持gif 文件,就只保留qgif4.dll 即可。 Qt Creator 的 error: collect2: ld returned 1 exit status 问题 利用Qt Creator 1.2.1( Built on Sep 30 2009 at 05:21:42)编译 程序经常会出现error: collect2: ld returned 1 exit status 的错误,但是 自己的程序没有一点问题,怎么回事呢? 如果这时退出软件,再重新进入,打开刚才的工程,重新编译, 就不会出现刚才的错误了。这应该是Qt Creator 软件的问题吧! 后来发现是因为上次执行的程序还在运行,你打开windows 的任 务管理器中的进程可以看见你刚才运行的程序还在执行,我们看不见,是因为它 在后台执行着。出现这个现象,是因为你写的代码的问题,比如在main 函数里 用了w.show();语句,就可能出现界面一闪而过,但它并没有关闭,而是在后台 运行,所以再次运行时就会出错。我们可以在资源管理器中将该进程关闭,或者 像上面那样直接关闭Qt Creator。 示例: #include #include "widget.h" #include "logindlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); loginDlg m; if(m.exec()==QDialog::Accepted) { Widget w; w.show(); } return a.exec(); } 执行后就会在后台运行。这时如果修改了代码再次运行程序,就会出现上面的错 误。 在任务管理器中可以看见自己的程序: 将该进程结束,然后在重新运行,就不会出错了。 正确的代码应该这样写: int main(int argc, char *argv[]) { QApplication a(argc, argv); loginDlg m; Widget w; if(m.exec()==QDialog::Accepted) { w.show(); return a.exec(); } else return 0; //关闭整个程序 } 这样新建的对象w 就不是局部变量了,这样运行程序w 表示的窗口不会一闪而过, 会一直显示。程序也不会再出现上面的错误了。 QT 常用问题解答(转) 本文是我前几天一个网友告诉我的,当时看了感觉好,就保存下来。今天再次查 看,感觉有必要把文章分享给各位学习QT 的朋友,因为网上好用的QT 资源真的 好少。 1、如果在窗体关闭前自行判断是否可关闭 答:重新实现这个窗体的closeEvent()函数,加入判断操作 Quote: void MainWindow::closeEvent(QCloseEvent *event) { if (maybeSave()) { writeSettings(); event->accept(); } else { event->ignore(); } } 2、如何用打开和保存文件对话 答:使用QFileDialog Quote: QString fileName = QFileDialog::getOpenFileName(this); if (!fileName.isEmpty()) { loadFile(fileName); } Quote: QString fileName = QFileDialog::getSaveFileName(this); if (fileName.isEmpty()) { return false; } 3、如果创建Actions(可在菜单和工具栏里使用这些Action) 答: Quote: newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); newAct->setShortcut(tr("Ctrl+N")); newAct->setStatusTip(tr("Create a new file")); connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); openAct->setShortcut(tr("Ctrl+O")); openAct->setStatusTip(tr("Open an existing file")); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); saveAct->setShortcut(tr("Ctrl+S")); saveAct->setStatusTip(tr("Save the document to disk")); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); saveAsAct = new QAction(tr("Save &As..."), this); saveAsAct->setStatusTip(tr("Save the document under a new name")); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(tr("Ctrl+Q")); exitAct->setStatusTip(tr("Exit the application")); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); cutAct->setShortcut(tr("Ctrl+X")); cutAct->setStatusTip(tr("Cut the current selection's contents to the " "clipboard")); connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut())); copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this); copyAct->setShortcut(tr("Ctrl+C")); copyAct->setStatusTip(tr("Copy the current selection's contents to the " "clipboard")); connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy())); pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this); pasteAct->setShortcut(tr("Ctrl+V")); pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current " "selection")); connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste())); aboutAct = new QAction(tr("&About"), this); aboutAct->setStatusTip(tr("Show the application's About box")); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); 4、如果创建主菜单 答:采用上面的QAction 的帮助,创建主菜单 Quote: fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct); fileMenu->addAction(openAct); fileMenu->addAction(saveAct); fileMenu->addAction(saveAsAct); fileMenu->addSeparator(); fileMenu->addAction(exitAct); editMenu = menuBar()->addMenu(tr("&Edit")); editMenu->addAction(cutAct); editMenu->addAction(copyAct); editMenu->addAction(pasteAct); menuBar()->addSeparator(); helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(aboutAct); helpMenu->addAction(aboutQtAct); 5、如果创建工具栏 答:采用上面的QAction 的帮助,创建工具栏 Quote: fileToolBar = addToolBar(tr("File")); fileToolBar->addAction(newAct); fileToolBar->addAction(openAct); fileToolBar->addAction(saveAct); editToolBar = addToolBar(tr("Edit")); editToolBar->addAction(cutAct); editToolBar->addAction(copyAct); editToolBar->addAction(pasteAct); 6、如何使用配置文件保存配置 答:使用QSettings 类 Quote: QSettings settings("Trolltech", "Application Example"); QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); QSize size = settings.value("size", QSize(400, 400)).toSize(); Quote: QSettings settings("Trolltech", "Application Example"); settings.setValue("pos", pos()); settings.setValue("size", size()); 7、如何使用警告、信息等对话框 答:使用QMessageBox 类的静态方法 Quote: int ret = QMessageBox::warning(this, tr("Application"), tr("The document has been modified.\n" "Do you want to save your changes?"), QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); if (ret == QMessageBox::Yes) return save(); else if (ret == QMessageBox::Cancel) return false; 8、如何使通用对话框中文化 答:对话框的中文化 比 如说,QColorDialog 的与文字相关的部分,主要在qcolordialog.cpp 文件 中,我们可以从qcolordialog.cpp 用 lupdate 生成一个ts 文件,然后用自定 义这个ts 文件的翻译,再用lrelease 生成一个.qm 文件,当然了,主程序就要 改变要支持多国语言了, 使用这个.qm 文件就可以了。 另外,还有一个更快的方法,在源代码解开后有一个目录translations,下面 有一些.ts, .qm 文件,我们拷贝一个: Quote: cp src/translations/qt_untranslated.ts ./qt_zh_CN.ts 然 后,我们就用Linguist 打开这个qt_zh_CN.ts,进行翻译了,翻译完成后, 保存后,再用lrelease 命令生成qt_zh_CN.qm, 这样,我们把它加入到我们的 qt project 中,那些系统的对话框,菜单等等其它的默认是英文的东西就能显 示成中文了。 9、在Windows 下Qt 里为什么没有终端输出? 答:把下面的配置项加入到.pro 文件中 Quote: win32:CONFIG += console 10、Qt 4 for X11 OpenSource 版如何静态链接? 答:编译安装的时候加上-static 选项 Quote: ./configure -static //一定要加static 选项 gmake gmake install 然后,在Makefile 文件中加 static 选项或者在.pro 文件中加上QMAKE_LFLAGS += -static,就可以连接静态库了。 11、想在源代码中直接使用中文,而不使用tr()函数进行转换,怎么办? 答:在main 函数中加入下面三条语句,但并不提倡 Quote: QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); 或者 Quote: QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK")); QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); 使用GBK 还是使用UTF-8,依源文件中汉字使用的内码而定 这样,就可在源文件中直接使用中文,比如: Quote: QMessageBox::information(NULL, "信息", "关于本软件的演示信息", QMessageBox::Ok, QMessageBox::NoButtons); 12、为什么将开发的使用数据库的程序发布到其它机器就连接不上数据库? 答:这是由于程序找不到数据库插件而致,可照如下解决方法: 在main 函数中加入下面语句: Quote: QApplication::addLibraryPath(strPluginsPath"); strPluginsPath 是插件所在目录,比如此目录为/myapplication/plugins 则将需要的sql 驱动,比如qsqlmysql.dll, qsqlodbc.dll 或对应的.so 文件放 到 /myapplication/plugins/sqldrivers/ 目录下面就行了 这是一种解决方法,还有一种通用的解决方法,即在可执行文件目录下写 qt.conf 文件,把系统相关的一些目录配置写到qt.conf 文件里,详细情况情参 考Qt Document Reference 里的qt.conf 部分 13、如何创建QT 使用的DLL(.so)以及如何使用此DLL(.so) 答:创建DLL 时其工程使用lib 模板 Quote: TEMPLATE=lib 而源文件则和使用普通的源文件一样,注意把头文件和源文件分开,因为在其它 程序使用此DLL 时需要此头文件 在使用此DLL 时,则在此工程源文件中引入DLL 头文件,并在.pro 文件中加入 下面配置项: Quote: LIBS += -Lyourdlllibpath -lyourdlllibname Windows 下和Linux 下同样(Windows 下生成的DLL 文件名为yourdlllibname.dll 而在Linux 下生成的为libyourdlllibname.so。注意,关于DLL 程序的写法, 遵从各平台级编译器所定的规则。 14、如何启动一个外部程序 答:1、使用QProcess::startDetached()方法,启动外部程序后立即返回; 2、使用QProcess::execute(),不过使用此方法时程序会最阻塞直到此方法执 行的程序结束后返回
中国象棋的C++代码 #include "chess_zn.h" QTcpSocket * Chess_ZN::client = new QTcpSocket; QUndoStack * Chess_ZN::undoStack = new QUndoStack(); int Chess_ZN::second = 120; bool Chess_ZN::isTurn = false; Chess_ZN::Chess_ZN(QWidget *parent) : QWidget(parent) { init(); initElse(); } void Chess_ZN::initElse(){ treeitem = 1; timer=new QTimer; portmap=0; isConn = true; start = false; isTimer = false; isSearch = false; connect(timer,SIGNAL(timeout()),this,SLOT(stopWatch())); connect(wigettree[1],SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(getInfo(QTreeWidgetItem*))); connect(wigettree[0],SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(connectToHost_PK(QTreeWidgetItem*))); connect(client,SIGNAL(connected()),this,SLOT(connected())); //连接一旦断开 connect(client,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error(QAbstractSocket::SocketError ))); connect(client,SIGNAL(readyRead()),this,SLOT(readyRead())); peer = new PeerManager(this); peer->setServerPort(10001); items=wigettree[1]->currentItem(); item_pk=wigettree[0]->currentItem(); item_pk_info=wigettree[0]->currentItem(); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[8], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[9], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[10], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),action2[11], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[0], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[1], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[2], SLOT(setEnabled(bool))); connect(undoStack, SIGNAL(canUndoChanged(bool)),button[3], SLOT(setEnabled(bool))); timer->start(1000); createUndoView(); isChoose = true; tableeditor=new TableEditor("users"); } void Chess_ZN::createUndoView() { undoVie
******************************************* ************ WPTOOLS 6 History ************ ********** http://www.wpcubed.com ********* **** Copyright (C) 2012 J. Ziersch and **** **** WPCubed GmbH, Munich, Germany ******** ******************************************* * - = bug fix * + = new feature * * = changed, expanded feature ******************************************* * IMPORTANT: Please edit file WPINC.INC to * activate WPREPORTER, WPSPELL, wPDF, TBX * and GraphicEx / PNGImage support! * Delphi 2009 and later as inbuilt PNGImage ******************************************* * THE MANUAL (PDF) AND REFERENCE (HLP,CHM) * ARE PROVIDED AS SEPERATE DOWNLOADS! ******************************************* ~~~~~~~~~~ Important Notes ~~~~~~~~~~~~ - With Delphi XE2 or XE3 it is possible to compile WPTools into a 64 bit applications. You need WPTools 6 PRO or WPTools 6 Premium for this. - Localization and Inch/CM selection see http://www.wpcubed.com/manuals/wp5man/index.html?localization.htm Also see demo\tasks\localization. There are the required XML files. - if flag wpDontAddExternalFontLeading is active in property FormatOptionsEx the text will be formatted more like WPTools4/MS-Word. You can alternatively set global variable WPDoNotAddExternalFontLeading := TRUE and select the Printer WYSIWYG mode: TWPRichText1.HeaderFooter.UpdateReformatMode(true) - The FormatOption wpDisableAutosizeTables can be required for good display of tables. wpNoMinimumCellPadding for narrow layout, too. - If you plan to use DBWPRichText please check http://www.wpcubed.com/forum/viewtopic.php?p=3456 - The reader/writer receive their options through "FormatStrings" please see list at http://www.wpcubed.com/manuals/formatstrings.htm - WPTools is configured using the file WPINC.INC, here WPREPORTER is activated and the optional WPShared, WPSPell and wPDF can be selected to be compiled into main WPTools package. - also see FAQ: http://www.wpcubed.com/forum/viewforum.php?f=15 - and support forum: http://www.wpcubed.com/forum/ - WPTools 6 PRO and PREMIUM will be compiled as Version 5 if $define "WP6" is not set ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We recommend to use TMS components to create modern user interfaces, toolbars and ribbons. 19.2.2013 - WPTools 6.29.1 - fix in rtf writing code to solve problem with merged cells - fix possible rangecheck error - fix problem with TextObject.LoadFromFile and Delphi XE3 * RTF reader now handles UNC file links which use "\\" in the path * the cursor was not painted if DoubleBuffered was set to true for the parent of the editor + WPTools Premium: Saves and loads \column * improved theming of TWPToolbar and TWPToolPanel + new event: OnPaintDesktopBackground. It can be used to draw the parent of the editor, for example if it is a TMS panel or pager control. Example: procedure TForm1.WPRichText1PaintDesktopBackground(Sender: TObject; Canvas: TCanvas; R: TRect); begin // This would paint the TWPRichText, too - but TWPRichText is locked for repaint during this event AdvOfficePager1.PaintTo(Canvas, -WPRichText1.Left, -WPRichText1.Top); end; - HighlightTextColor can now also be used if 2Pass Painting is used 21.12.2012 - WPTools 6.29 - images in RTF label were not painted when label was moved + added support for XE3 to WPTools STD edition * stream RTFvariables were not loaded from WPT format. They are loaded now. 9.11.2012 - WPTools 6.28 - Update to RTF reader to load landscape flag for sections better - when page mirror was used, after a page break the text indentation was sometimes wrong - hyphenation code was broken - workaround for word files which have space characters in table definitions 16.10.2012 - WPTools 6.27'' * some additions to the PRO edition for XE3 26.9.2012 - WPTools 6.27' * The PRO Version now supports Delphi XE3 3.8.2012 - WPTools 6.27 - fix for wrong display of tables with header and footer rows. Sometimes both were painted without any data. + to load old Hiedit templates as RTF code use the formatstring -HiEditFields. This will create merge fields for ALL fields. - NL sign was not shown right after CTRL+ENTER was pressed (requires ShowNL) - fix for rangecheck exception with paintpages array - fix for footer and page mirror - doubleclick word selection now stops at NL - Workaround for Windows Spooler problems - some images would get lost - sections use footer and header of previous section, not general - ASetBorder did change all border types 12.3.2012 - WPTools 6.25.4 * allows changing of column width in redonly editors. Can be switchoed off in EditOptions or set compiler define TOTALREADONLY + wpDisableSelectAll in EditOptionsEx2 * changed reformat/repaint after Undo/Redo - pro and premium: Due to a problem with precompiler cursoir selection did not work correctly 8.3.2012 - WPTools 6.25.3' - borders for paragraphs with multiple lines were not drawn correctly - change in DBWPRich.pas to use LoadFromString instead of Text - fix possible range check error - change in WPTbar.pas to use different default for BevelOuter - change in WPIOHTML to use default charattr of paragraph is a paragraph is empty 9.2.2012 - WPTools 6.25.2 * new 2-pass painting triggers CustomPaint event only on second loop (when the text is painted) * changed protection of empty paragraph to WPTools 5 way + inside of the OnPrepareImageForSaving event it is now possible to set Writer.CurrentImageName to the name of the file which should be saved. This is only useful if ObjRef = nil and so no ObjRef.Filename can be set. + TParagraph.GetSubText now has optional parameter to disable the object reference char codes #1, #2 and #3 * HTML writer ignores #13 codes when writing the text. * additional savety code in HTML writer * HTML reader sets image width and height to contents, (if possible) * HTML reader: changes UTF8 handling for UTF8Sequence=1 * HTML reader does not stop on \0 anymore * HTML writer writes img tag also for empty images IF a name is provided in event PrepareImageforSaving * HTML reader does not add space at end anymore - the UNICODE reader uses attribute of current paragraph. This is important for consistent behaviour between ANSI and UNICODE version - when writing HTML background color is not set to white when shading is 0. 0 is treated as default value. - image align center and right now works in HTML - fix an endless loop when image was too large - improvement of table border drawing - improvement for right align in table cells + numbering will be used when wpFormatAsWebpage was set in AsWebpage 10.1.2012 - WPTools 6.25 + HTML reader reads cell heighs - RTF writer writes background color easier to understand by Word * improved XML reader/writer (unit WPIOXml1) * improved word wise cursor movement when fields are used + new "paint attributes" mode. Use WPRichText1.BrushStart to select this mode. - dashes were not painted using the current font color - some stability improvements 7.11.2011 - WPTools 6.22 + procedure TParagraph.CellSelectionAdd; + procedure CellSelectionRemove; + EditOptionsEx2: wpCellMultiSelect - allows multiselection in tables when CTRL is pressed + improved XML import/export (unit WPIOXML1.PAS) - some smaller bugs fixed 3.11.2011 - WPTools 6.21.2 - fix problem with TWPToolButton - improved HTML writer to write parameters in "" - improved display of arabic text 24.10.2011 - WPTools 6.21.1 - fix problem when painting insertpoints after tab stops. They were painted two times. - fix in XML and HTML writer. Close tags when extracting text from fields 19.10.2011 - WPTools 6.21 + CodeLocate can now also accessed in non-visual TWPRTFDataCollection and not just TWPCustomRtfEdit + CodeSelect can now also accessed in non-visual TWPRTFDataCollection and not just TWPCustomRtfEdit + TWPRTFDataCollection.CodeLocatePair( FormatName : String; var spar, epar : TParagraph; var spos, epos, : Integer ) :Integer; - solves problem with integrated Bin64 decoder + DeleteField now has optional "Contents" parameter to delete a certain field with contents + the text writer now understand the option -softlinebreaks to create a \n at the end of every line. In fact all soft line breaks will be handled like the #10 code. + CodeLoadSaveEmbeddedText - load or save text in fields, bookmarks, hyperlinks + the regular save and load methods (LoadFromFile, SaveToFile) can now access text wrapped by paired objects. specify the fieldname in the format string, i.e. "f:name=RTF" to save or load the contents of the field "name". + There is an overloaded LoadFromString which expects a WideString as parameter (Delphi 6+) - The Setup named the Delphi 2009 files "Delphi 2005" due to a typo. (Delphi 2005 units are not included anymore) - fix probable range check error in WPRTEDEFS 13.10.2011 - WPTools 6.20 + completely new setup procedure. The PRO and Premium releases don't include object files which makes them much smaller. * compiled new WPTools 6 Reference (CHM file) * Delphi XE2: several small changes to improve theming support * Delphi XE2: several small changes to provide compatibilty to 64bit compiler (requires WPTools PRO) + new demo developed with Delphi XE2, showcases actions, splitscreen, simulated MDI and property dialogs (Demos\XE2\WPWord) + wpDeleteAtEOFRemovesSpaceAfter in EditOptionsEx2 - TextObjectsGetList did not work * WPRuler uses Delphi XE2 VCL Theme plus * added defaults to properties TWPRichText - change in RTF reader to let section inherit the default layout, not the current page layout - fix of problem with table borders when also PageMirror was used. * change to DeleteMarkedChar. It now has additional parameter DeleteEmptyParAndTables : Boolean * change in unit WPWordConv to handle RTF as DOC files if they do not start with "{\rtf" * updated border dialog TWPParagraphBorderDlgEx * updated border drawing code - now supports dotted lines with wider lines. * modified method DeleteColumn * modified WPT reading code to repair table width which were negative + improved image rendering code for transparent (PNG) images. They will be drawn transparently also when scaled and also in high resolution rendering mode. + new code to draw dotted lines which also supports wider lines + new function WPReplaceTokens (unit WPUtils.PAS). It is a ReplaceTokens function to be used on a TWPRTFDataCollection, not TWPRichText - WPPremium - fix problem when there were too columns * MergeText now restores before Merge Cursor position and selection (except for cell selection) * resizing a table column does not move the cursor to the nearby cell anymore * different frame line when resizing columns and rows + InsertColumn now also works if wpAllowSplitOfCombinedCellsOnly was used in EditOptionsEx + new event OnPaintTextFrameRect let you paint background and borders for text frames, i.e. the text body or, with WPTools Premium, custom frames. + WPPREMIUM: In OnMeasureTextPage it is possible to set columns for certain pages. Using PageInfo.colflags=1 it is possible to activate a line between the columns It is also possible to add custom frames using PageInfo.rtfpage.AddFrameRect. + new ViewOptionEx: wpHideParBordersBeforAndAfterPageBreaks + improved paint routine now avoids clipping of characters which were overlapping their bounding box, such as italic letters or "f". The improvement is especially visible when selecting text or using character background colors + WPPREMIUM: it is now possible to print a line between columns using wpShowColumnCenterLine in ViewOptionsEx + With WPTools Premium it is now possible to print a line between certain colums - use par.ASet(WPAT_COLFLAGS, WPCOLUM_LINE); + paragraph styles can now contain border definion for paragraphs + TWPTextObjList now has a IndexOfSource function and a Source[] string array to access the objects * revised code to draw double borders - always draws twou lines on screen even when zoomed * improved saving of numbering attributes with styles * style dialog can now apply number level even if style does not have numbering yet. * revised wpNoEditOutsideTable - was not checked for keyboard input * fix problem with - - - - - at end of line - fix problem with spell-as-you go after hyperlinks - fix problem with page numbers in sections when tables were spanning pages - fix problem with right aligned negative numbers in merge fields * automatic text attribute was not inherited to tables inserted in fields * images with mode "under text " can now be also clicked at positiones where there is no text. - WPLngCtr now defines DONT_OVERRIDE_COM, that fixes the IDE problem with DevExpress Toolbar controls 18.7.2011 - WPTools 6.16.2 * ObjectMode wpobjPositionAtCenter can be used to aligh character based images to the center line. (Other RTF reader will not understand this feature) * some changes to prepare 64bit compatibility (requires WPTools 6 PRO) 7.7.2011 - WPTools 6.16.1 * change to avoid flickering when doing auto scroll * message strings are now loaded from resource strings - modified DBCS support for RTF reader * outerborder action now works for sinle cells and paragraphs 15.6.2011 - WPTools 6.16 + Many improvements to new Border Dialog. It is now possible to apply borders and colors to odd and even rows only. * RTF reader defines symbol IGNORE_AUTOWIDTH_TBL. This disable the Word2010 auto width columns which are not read correctly. Reason: Word 2010 seem to always add an empty column to the end. + using WPRichText1.Caret.Blink:=true it is possible to activate the blinking caret (0.5sec interval). * updated actions to apply inner and outer borders to selected cells * update to ExSymbolDialog, Tab and Table dialog - improved WPTOOLS reader to read and apply outline properties to current outline setting (unless wpLoadDoesNotOverride is used) - wpsec_ResetPageNumber flag is now saved in WPTOOLS format * tripple click in margin selects paragraph + double click in margin selects current cell + tripple click in margin selects current row - change for PaintEngine and TWPRichTextLabel to not shrink tables which are small enough to fit the page This solves a problem with dissapearing text in WPRichTextLabel - fix selection problem when several images were linked to same paragraph - when moving images the Z order will not be reset - HTML Writer: A style with name "DIV" will be added to the style sheet to save the default font - HTML Writer: BaseFont tag will now be written with font size (requires -writebasefont option) - improved display of character background color for fields and other special code - Saving a style sheet did not work with Unicode Compiler 8.5.2011 - WPTools 6.15 * updated border painting * updated Inner/Outer Border Action * new object sizing routine lets the user make the size larger than the page - update in WPTools reader to overwrite outline styles when loading tzhe same group 9.3.2011 - WPTools 6.14.6 * change in format routine to fix problem when a nested table cell caused a page break. 14.12.2010 - WPTools 6.14 * fix for SetAsString code (Unicode Delphi) * several fixes and updates in editor * WPTools Premium: $define DONT_AUTOENTER_TEXTBOXES in WPINC.INC to switch of the behavior, that when editing a textbox the user can click on any other and edit that. 22.9.2010 - WPTools 6.13.3 * WPCtrMemo.PAS now defines TEXT_IS_UNICODE fro Delphi 2009 and later. Now the property Text and SelText reads and writes unicode strigs * change in RTF reader to read ANSI characters in the range 128..255 * Tables and rows can now be hidden. (TParagraph.Hidden) * The Lines property now supports unicode strings (Delphi 2009 and later) + HTML reader and writer now use the entitly ­ as soft hyphen 27.8.2010 - WPTools 6.13.2a + new ViewOptionEx wpUnderlineWebLinks. If active links like http://www.wptools.de will be drawn using the attributes for hyperlinks The HyperlinkCursor will be selected and the hyperlink event will be triggered * other fixes in RTF engine - Memo._OverrideCharset was not set to -1 27.7.2010 - WPTools 6.13.1 + WPRichText1.Memo.ColorGridLines can be used to change the color of the grid lines (ViewOptions) 23.7.2010 - WPTools 6.13 * several improvements of editor * improvement to RTF writer to when writing table cells * improved right aligned text * fixed problem with line heights of lines which are empty except for new line character 22.6.2010 - WPTools 6.12.1b - fix for problem when pressing Accent + Backspace - fix for WPReporter to assign default attribute to destination - fix for WPReporter to move images when converting templates 18.6.2010 - WPTools 6.12.1a * the new border dialog now reads the current border attributes from table cells, tables or selections - Premium: fix problem when loading columns which started on first line - fix in wpfUseKerning mode (FormatOptionsEx2) - it did not work as expected with some texts (We recommend to use wpfUseKerning - it produces better print quality on screen) * Pasting of HTML now works better - fix for right tabs when also borders were used 13.6.2010 - WPTools 6.12 + all new, powerful yet intuitive Border dialog. The border dialog can modify a range of selected cells, columns, rows, tables and also only modify certain properties while leaving the others unchanged. You need to activate the compiler symbol NEWBORDER to use it by default + new method: procedure SetBorderProperties(Inner, Outer: TWPTextStyle; ApplyMode : TWPParagraphBordApply; Mode : TWPUpdateBorderProperties = [wpSetBorderFlags, wpSetBorderType, wpSetBorderWidth, wpSetBorderColor, wpSetParColor, wpSetParShading]); This method is mainly used by the new border dialog. + new flags in ViewOptionsEx: wpShowCurrentCellAsSelected, // Displays current cell to be selected. Disables current selection wpShowCurrentRowAsSelected, // Displays current table row to be selected. Disables current selection wpShowCurrentTableAsSelected // Displays current table to be selected. Disables current selection + new property YOffsetNormal to defined an upper border for normal and wordwrap view. * feature Header.MarginMirror changed to work like MS Word new flag: wpMarginMirrorBookPrint in FormatOptionsEx2 to enable the previous logic * workaround for MouseWheel UP beeing triggered too often (10 mms check) + ClipboardOption wpcoDontPasteHTML to disable HTML pasting completely (avoid problems with firefox) + it is now possible to load base64 embedded JPEGs from HTML * it is now possible to change width of tables which exceed right margin - fix bug in HTML writer for lists in table cells - fix in RTF writer to write character colors also for text which is using a character style - fix: numbering was not always updated - fix: better use fonts in certain RTF files written by MS Word + Update to WPLanguageControl to make Localization easier to use. Only< this code is not required: procedure TForm1.WPLanguageControl1Loaded(Sender: TObject); begin WPLangInterface := TWPLocalizationInterface.Create(WPLanguageControl1); WPLocalizeAllStrings; end; 6.5.2010 - WPTools 6.11.2 * improvement to border rendering * improvement to XML unit WPIOXML1 (Premium) 5.5.2010 - WPTools 6.11.1 + ConvertTableToText now supports option to also handle soft line breaks - fix problems with underlines at end of line - fix problem when loading hyperlinks in RTF - fix problem when saving attributes to XML (WPTools Premium) - fix problem with text rendering - fix problem with tables which habe header row and pages with different header margin 19.4.2010 - WPTools 6.11 + EditOptionEx: wpRowMultiSelect + new event: OnInternPaintPar + new event: RTFDataCollection AfterApplyUndoObject 14.4.2010 - WPTools 6.10.6 * fields are now passed as unicode strings to PDF exporter * Delphi 2010/2009 import has been improved to load unicode values which are stroed in fields. 5.4.2010 - WPTools 6.10.5 + flag: wpDontExtendSelectionToRightMargin. Do not extend selection to end of line + wpInvertActiveRow in ViewOptionsEx - some fixes for Delphi 2009 and Delphi 2010 - fix for section support - WPTools premium: Fix for images in text boxes - workwaround to load RTF which use emfblib for pngblib 28.2.2010 - WPTools 6.10 - improve word left/right movement to skip hidden text - improve http load of images - improve support for numbering - improve saving of character style attributes 11.2.2010 - WPTools 6.09.1 + LoadFromString now has a "WithClear" parameter - fix in RTF reader to better load files which do not define codepage - fix in paint routine to solve a rare lockup - fix in format routine to improve section support 6.2.2010 - WPTools 6.09.1 - fix of problem in save routine when footnotes were used (WPTools premium) - fix in HTML writer - Image optiions now have a Rotation property which allows 90, 180 and 270 setting. - HTML reader and writer now support different colors for left,right,top, bottom lines 1.2.2010 - WPTools 6.09 - HTML writer will write 8 hard spaces for TAB stops at the start of a paragraph - HTML writer will write page information only if -PageInfo was used in format string - fix problem with left aligned text and image wrap around (wrong alignment) - fix problem with sometimes duplicated images in PDF export - fix problem with black rectangle in first line under Windows 7, 64 bit - Improvment to RTF reader to ignore section properties which are not followed by \sect 14.12.2009 - WPTools 6.08 - graphics are resized to fill text area - fixed problems in numbering - fixed problem with one word paragraphs in justified paragraphs - other improvements in editor 27.10.2009 - WPTools 6.07 - fixed one leaking TList per TWPRichText * improved layout of most important dialogs * improved extended insert symbol dialog - fix in RTF reader to load sections and header+footer written by Word 2003 - don't add unwanted cell padding when loading table cells - fix in WPTools reader to read custom number styles - if paragraph styles use number styles the indent defined in the style has priority over numberstyle - LabelDef now also works for one row and one column - better handling of mousewheel event - fix for tabs in tables + GIF animation (requires GifImage) library (not threaded) to use it You need to set ViewOption wpUseOwnDoubleBuffer and call the method RefreshAniImages using a timer object. - fix problem when sections were used with LabeDef.Active = true * change in HTML writer to close tags before paragraph end 4.10.2009 - WPTools 6.06 - fix problem with Delphi 2010 support (language control) - fix problem with PDF export to reduce PDF size - improve support for IME * improve AsWebPage format mode. Now WordWrap propery is supported. - fix searching text upwards with "Whole Word" selected + RTF writer now can use format option "-writehighlight" to writh \highlight instead of \cb 14.9.2009 - WPTools 6.05.9 + added Delphi 2010 Support - problem when pasting from "The Bat" - fix problem in Delphi 2009 (Assign Method) 3.8.2009 - WPTools 6.05.8' * when using "Delete All" in the tabstop dialog, all tabs will be cleared added to manual: Tabstop Category - fixed problem when deleting text in a paragraph. The alignment was cleared unexpectedly. - fix problem with installer, WPMangeHeaderFooter.DFM was not included - fix for IPara in mail merge field objects - improved handling of hoover effect for hyperlinks - improved text rendering for wPDF output (CID Mode) - add correct WPManHeadFoot.dfm 23.7.2009 - WPTools 6.05.7 + WRITE_PROP_WPTOOLSOBJ $define in WPIOWriteRTF. Avoid problems when saving RTF and opting in Word In case of special objects, such as SPAN codes, \*\wpfldinst is beeing written what is ignored by WOrd + Dialog HeaderFooter can optionally create and manage header&footer for the current section + new KeepN Handling. This is by default activated in FormatOptionsEx2 + new wpfHideParagraphWithHiddenText in FormatOptionsEx2. Now paragraphs will be hidden if empty or only contain hidden text. + new format option -zap1 will remove the every first byte to convert a two byte stream into singly byte -zap2 will remove every second byte. Usie this option when loading data from unicode data sets - bugfix for table loading in RTF 15.7.2009 - WPTools 6.05 + TParagraph.Trim method to remove white spaces at start and end + Vertical Scrolling by pressing the middle mouse button now works. + improved auto thumbnail mode * enhancement to HTML reader / writer to handle embedded SPAN objects + new method: ApplySPANStyles(and_remove : Boolean=false; ignore_charattr : Boolean = false); can be used to apply SPAN styles to the text which it embeds + The function InputSpanObjects( Attributes : TWPAbstractCharAttrInterface ) : TWPTextObj; can be used to wrap the selected text into SPAN objects + method LoadCSSheet can be used to load paragraph styles in CSS format from a string - fix problem with Wordrwap and centered text + new even OnTextObjectMovePosition (move event) - OnTextObjectMove is still used for resize (unchanged) 28.6.2009 - WPTools 6.04 + WPTools Premium: Column Balancing * many improvements in RTF reader. Word documents are now understood better * Improvement in check for protected text (ppMergedText) + new ViewOptionsEx property - auto hyperlinks were not working + TWPComboBox has an event OnUpdateItems which will be triggered after the items had been automatically assigned. 24.6.2009 - WPTools 6.03.6 * thinner page borders in thumbnail mode. ViewOptionsEx: wpAutoThumbnailMode will show pagenumbers only when in thubmbnail mode (= wpShowPageNRinGap in ViewOptions) + property ColorDesktop and DeskGradientHorizontal to render the background with a gradient fill * fix for protected text handling (CR after a field) * fix for text alignment near a movable image - EditOption AutoDetectHyperlinks was not working anymore * WPReporter: SuperMerge.Stack.PageBreakAFterGroup := true was ot working when footers were used 1.6.2009 - WPTools 6.03.5 - fix problem with display of character attributes when attributes were inherited from paragraph styles - fix problems with selection deletion in single column, single row tables - improvement of RTF writer when writing sections 11.5.2009 - WPTools 6.03.3 - improved report band dialog, new ShowOptions property - fix in RTF reader to load header/footer - change in HTML writer to save SPAN instead of FONT tag - several fixes in editor * WPTools Premium: better column support. Fixed column height now splits correctly on 2 pages. 28.4.2009 - WPTools 6.03.2 - fix problem with justified text in PDF 21.4.2009 - WPTools 6.03.1 - fix problem with images when used in Delphi 2009 - better support for header/footer in RTF files created by word. (Ignore bogus header/footer) - soome stability fixes 25.3.2009 - WPTools 6.03 + improved text rendering - optimation for character distances on screen to provide better display + improvement on ShowMergeFieldNames to improve cursor movement and drag and drop + automatic disable dragging of fields inside of fields + improved merge field selection. TextObject.SelectedObject now returns the mergefield if it was completely selected + change in HTML saving code to save src in after width adn height (for outlook) * various bugfixes 17.1.2009 - WPTools 6.02 - WPPREMIUM: Text after Columns initialized with WPAT_COLUMNS_Y is now allowed + TWPToolBar FontName drop down now lists fonts used by document first - fix for tables which use a fixed row height and are splitted on different pages + improvements necessary for Delphi 2009 - the Locaization demo now works + EditOptionEx wpDontPreserveObjectsAgainstDeletion - fix problem in ImageObject LoadFromStream when GraphicEx is used - fix problem with Delphi 2009 when loading WPReporter templates - fix problem with HTML reader with paragraph style of first paragraph + GetFontUnicodeRanges dynamically linked to avoid Win98 problem 26.10.2008 - WPTools 6.01 * updated HTTP Demo, now with "Source View" + DELETE/BACKSPC at start of line removes right/center alignment + loads background images for paragraphs, tables and styles * improvement to text protection (empty lines) - improvements to HTML and CSS reader - improved HTML format routine - improved MIME loading - now supports binary data despite Synapse does not) + MIME reader capturesHTML body for SourceVIew * DataProvider now uses MergeText('',true) instead of MergeText + boolean wphttp_Disable to disconnect HTTP temporarily * several changes to improve compatibility with Delphi 2009 17.10.2008 - WPTools 6.00.1 - several changes to fix problems which occured with use of Delphi 2009 * update to WPIO_MIME to also load binary encoded GIFS and JPEGS from EML files 16.10.2008 - WPTools 6.00 * new installer + VCL demo * fixed problem with TWPComboBox and default attributes * updated "Tasks\Mini" demo project - fix in default actions 3.10.2008 - WPTools 6 Beta c - remove not required unit reference form WPRTEReport * update to manual 2.10.2008 - WPTools 6 Beta b - fix in Installation script 30.9.2008 - WPTools 6 Beta a 1) Application-Server-Mode WPTools 6 introduces a feature which is called "Application-Server-Mode". This is only available when you have the PREMIUM version. This mode is activated when true is assigned to the global boolean variable WPAppServerMode. When this mode is activated the editor does not use the double buffered output anymore. While this can cause some flickering the network traffic is reduced when the application runs on an application server, such as Citrix. Please note, effective with WPTools 6, software which was written for application servers (such as clinic software) may only be distributed when a TEAM or SITE license of WPTools was acquired.END 2) Integrated Label Printing When activated the integrated label printing shows multiple labels on one virtual sheet of paper. The cursor can move from label to label freely. The user can so edit the labels, add new or delete unwanted labels before the complete sheet is printed. This is a very unique and versatile feature. 3) Additions to the PDF export with wPDF V3 Create embedded data objects Create edit / memo fields Create a check box field Also the creation of PDF tags was enhanced. So now hints to paragraph styles will be also exported. 4) Additional Control over Clipboard Actions a) properties to select the format b) added security 5) Added Section API + WPRichText1.ActiveSection + WPRichText1.InputSection + TWPPagePropDlg has new method ExecuteEx. Use it to change current page size or Section WPPagePropDlg1.ExecuteEx(WPRichText1.ActiveSection); 6) Load over HTTP connections (requires Synapse) 7) Load and save MIME encoded HTML with embedded images (requires Synapse) 8) Integrated XML syntax highlighting (non destructive) 9) WPReporter: Token to Template conversion with syntax highlighting 10) Additions to paragraph API 11) Special mode to format HTML documents
启点CE过NP中文December 24 2018:Cheat Engine 6.8.2 Released: Here's a new version for the hollidays. Mainly minor improvements and some small bugfixes, but also a new 'ultimap like' feature called Code Filter for which you don't need any special hardware for. (Just an extensive list of addresses) Download: Cheat Engine 6.8.2 Fixes: Disassembler: Several disassembler instructions had a comma too many or too few ,fixed those Disassembler: Fixed the description for ret # Disassembler/Debug: Fixed the address that is being edited when a breakpoint hits while editing an instruction Assembler: Fixed assembling reg*2/4/8+unquotedsymbol Plugin: Fixed the SDK for C plugins that use the disassembler callback Hotkeys: Fixed the attach to foreground hotkey Memory Scan: Fixed the percentage scan Memory Scan: Fixed a rare situation that could cause an error Memory Scan: Simple values now works with groupscan Memory Scan Lua: Scanfiles now also get deleted if the memory scan object is freed before the scan is fully done Fill Memory: Now allows 64-bit addresses Structure Dissect: Fixed the popupmenu "change type" so it now affects all selected entries instead of just the first PointerOrPointee window: Fix the debug pointer or pointee window button text when using access instead of writes GUI: Fixed and restored the DPI Aware option in setting GUI: Some DPI fixes/adjustments here and there Graphical Memory view: Fixed DPI issues Symbolhandler: When the symbolhandler now waits till it's done, it won't wait for the structures to be parsed anymore Additions and Changes: Lua Engine: Added autocomplete DLL injection: On DLL injection failure CE tries to fall back on forced injection methods Assembler: Added multibyte NOP Plugins: Plugins can now have side dll's that are statically linked in their own folder (Windows 7 with updates and later) Debugging: Improved the FPU window editing when single stepping, allowing you to change the FPU registers Debugging: Threadview now updates when single stepping and cnanges made there will affect the currently debugged thread (before it didn't) Debugging: Added Code Filter. This lets you filter out code based on if it has been executed or not (Uses software breakpoints) Debugging: Added an option to chose if you wish to break on unexpected breakpoints, and if CE should break on unexpected breakpoints, or only on specified regions (like AA scripts) Disassembler: The comments now show multiple parameters Pointerscan: Add option to allow negative offset scanning Pointerscan: Add extra types to the display Advanced Options/CodeList: Now uses symbolnames Tutorial Game: Added a levelskip option when you've solved a step Tutorial Game: Added a secondary test Compare memory: Added a limit to the number of address values shown per row (can be changed) Address List: When the option to deactivate children is set, the children will get deactivated first Memory Scan: Add a lua script in autorun that lets you specify which module to scan Lua: ExecuteCodeEx(Let's you execute code in the target and pass parameters) Added 2 new parameters to getNameFromAddress (ModuleNames and Symbols) Added addModule and deleteModule to the symbollist class Added the ModuleLoader class which can force load dll's Fixed endUpdate for the listview Thanks go out to SER[G]ANT for updating the russion translation files already June 23 2018:Cheat Engine 6.8.1 Released: Apparently 6.8 contained a couple of annoying bugs, so here's an update that should hopefully resolve most issues. Also a few new features that can come handy Download: Cheat Engine 6.8.1 Fixes: Fixed several issues with the structure compare Fixed the commonality scanner from picking up unrelated registers for comparison Fixed speedhack hotkeys Fixed ultimap 1 Fixed a bunch of random access violations Fixed Lua dissectCode.getStringReferences now also returns the string Fixed Lua breakpoints that specify a specific function Fixed Lua toAddress when the 2nd parameter is an address Fixed assembling xmm,m32 Fixed issue when disassembling AVX instructions Fixed rightclicking r8-r9 in the registers window Fixed the plugin system for DBVM Fixed DBVM memory allocations when smaller than 4KB Additions and changes: Added translation strings for the all type settings You can now drop files into the auto assembler auto assembler commands allocnx (allocate no execute) and allocxo (allocate execute only) The memoryview windows's hexadecimalview now shows the allocationbase as well, and can be doubleclicked to go there Added support for mono dll's that do not export g_free Changed "make page writable" to multiple options Improved DBVM speed slightly Lua: added RemoteThread class object June 8 2018:Cheat Engine 6.8 Released: Cheat Engine 6.8 has been released. Lots of new features like structure compare, AVX disassembling support, lua functions, etc... Download: If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker or by e-mail. And if you have questions, don't hesitate to ask them in the forum Fixes: Fixed some more high dpi issues Fixed issues with the dropdown list in memory records Fixed pointer offset symbols not calculating properly Fixed registered binutils Fixed graphical issues with the tablist Fixed issue where memory blocks would get cut of before the page end Fixed some memory leaks Fixed some graphical issues in the addresslist Fixed rightclick on r8 and r9 in memoryview Fixed disassembling some instructions Fixed DBVM so it works on windows 1709 and later (tested on 1803) Fixed several DBVM offload crashes Fixed freeze with allow increase/decrease for 8 byte long values Fixed several issues where minimizing a window and then close it would hang CE Fixed file scanning Fixed crashes when editing memory in some some emulators Additions and changes: Text editor improvements Added hundreds of new cpu instructions Mono now has some new features like instancing of objects Mono instances window is now a treeview where you can see the fields and values "find what addresses this code accesses" can also be used on RET instructions now (useful to find callers) The graphical memory view now has a lot more options to set it just the way you need Codepage support in hexview structure data from PDB files can now be used, and are stored in a database for lookup later dissect structures form can now show a list of known structures (pdb, mono, ...) Added a "revert to saved scan" option (lets you undo changes) Added a "forgot scan" option (in case you forgot what you're doing) Pointerscan limit nodes is default on in a new ce install (remembers your choice when you disable it) Autoattach now happens using a thread instead of a gui blocking timer Some colorscheme enhancements Added a DBVM based "Find what writes/accesses" feature. (For pro users, enable kernelmode options for it to show) Changed the dissect data setup from seperate yes/no/value dialogs to a single window Added a bypass option for ultimap2 on windows 1709. When using ranges, do not use interrupts, or use DBVM Added find what writes/access to the foundlist Autoassembler scriptblocks are now grouped when written to memory Added {$try}/{$except} to auto assembler scripts Added an extra tutorial/practice target Added cut/copy/paste context menu items to pointer offset fields in add/change address, and added a context menu to the pointer destination Added an automated structure compare for two groups of addresses to find ways to distinguish between them lua: added automatic garbage collection and settings to configure it added new functions: gc_setPassive gc_setActive reinitializeSelfSymbolhandler registerStructureAndElementListCallback showSelectionList changed the getWindowlist output MainForm.OnProcessOpened (better use this instead of onOpenProcess) enumStructureForms cpuid getHotkeyHandlerThread bunch of dbvm_ functions (needs dbvm capable cpu, and intel only atm) and more, including class methods and fields (read celua.txt) Minor patches: 06/08/2018: 6.8.0.4 - Fixed speedhack hotkey speed asignments and some commonalityscanner issues 06/09/2018: 6.8.0.5 - Fixed only when down speedhack option 06/10/2018: 6.8.0.6 - Fixed ultimap1 - Fixed ultimap2 on some systems - Fixed enableDRM() from crashing - Fixed one disassembler instruction Russian translation has been updated November 13 2017:Can't run Cheat Engine There is apparently some malware going around that blocks execution of Cheat Engine (Saying file missing, check filename, etc...) If you have been a victim of this then try this windows repair tool to fix your windows install: Download Repair Tool November 9 2017:Spanish(Latin) translation added Manuel Ibacache M. from Chile has provided us with spanish(Latin) translation files for Cheat Engine. They can be downloaded from the download section where you can find the other translation files, or right here June 7 2017:Cheat Engine 6.7 Released: Cheat Engine 6.7 has been released. New lua functions, GUI improvements, codepage scanning, several bugfixes and more(See below). Download: Cheat Engine 6.7 If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker, irc or by e-mail. And if you have questions, don't hesitate to ask them in the forum , irc Fixes: Fixed some DPI issues at some spots Fixed the "Not" scan for ALL "simple values" now also applies to the All type Fixed not adding the 0-terminator to strings when the option was set to add it Fixed ultimap hotkeys Fixed ultimap2 filtering Changing pointers in the change address dialog won't set/override global memrec and address anymore (local now) Fixed show as signed not working for custom types Fixed several issues with the structure spider Fixed 64-bit registers in the tracer getting truncated on doubleclick, and fix r8 to r15 Fixed copy/paste in the scanvalue Fixed kernelmode QueryMemoryRegions for windows build 1607 Fixed some disassembler errors Fixed lua command fullAccess Fixed text to speech if launched from a different thread Fixed clicking on checkboxes when the dpi is different Fixed the found code dialog count size Fixed mono freezing Cheat Engine when it crashes/freezes Additions and changes: Changed the processlist and added an Applications view similar to the taskmanager Small change to the tutorial first step wording Structure Dissect: Added RLE compression (by mgr.inz.player) and other things to improve filesize Structure Dissect: If setting a name, it will also be shown in the header The symbolhandler can now deal with complex pointer notations Added support for single-ToPA systems for ultimap2 Added some more spots where the history will be remebered in memoryview Memoryrecords with auto assembler scripts can now execute their code asynchronous (rightclick and set "Execute asynchronous") Kernelmode memory reading/writing is safer now Added an option to filter out readable paths in the pointerscan rescan Added "codePage" support Added font/display options to several places in CE Added a search/replace to the script editors You can now delete addresses and reset the count from "Find what addresses this code accesses" Added a statusbar to the hexview in memoryview Pointerscan for value scans now add the results to the overflow queue Opening a file and changing bytes do not change them to the file anymore (you need to explicitly save now) Added an option to the processlist to filter out system processes Added a system to let users sign their tables so you know you can trust their tables. Memory record dropdown lists can now reference those of others. USe as entry text: (memoryrecorddescription) Added an option to notify users of new versions of Cheat Engine lua: Custom Types can now be referenced from Lua Auto assembler lua sections now have access to "memrec" which is the memory record they get executed from. Can be nil stringToMD5String now support strings with a 0 byte in them autoAssemble() now also returns a disableInfo object as 2nd parameter. You can use this to disable a script added Action and Value properties to MemoryRecordHotkey objects added screenToClient and clientToScreen for Control objects added readSmallInteger and writeSmallInteger added enableDRM() added openFileAsProcess/saveOpenedFile added saveCurrentStateAsDesign for CEForm objects added disableWithoutExecute and disableAllWithoutExecute added OnCustomDraw* events to the listview added being/endUpdate for the Strings class added SQL support added color overrides to the disassembler text added OnPaint to the CustomControl class added autoAssembleCheck to syntax check an AA script fixed the addresslist returning nil for PopupMenu (while popupMenu did work) added an timeout option for pipes added some graphical options added some low level system functions Russian translation has been updated Chinese translation has been updated May 15 2017:Korean language files Thanks to Petrus Kim there are now Korean language files for Cheat Engine. You can get them here Just extract it to the language folder in the Cheat Engine installation folder and you'll be able to use it April 13 2017:Cheat Engine for Macintosh download For the Mac users under us there is now a mac version available for download. It's based on Cheat engine 6.2 but I will be upgrading it to 6.6 and later based on the feedback I get. Tip:if you have trouble opening processes: Reboot your Mac and hold CMD+R during boot to enter the recovery console. There open the terminal (using the top menu) and enter "csrutil disable" . Then reboot and you'll be able to open most processes (Youtube video by NewAgeSoldier in case it's not clear) October 6 2016:Cheat Engine 6.6 Released: Cheat Engine 6.6 has been released. It has several fixes, new scan functionality, gui changes/improvements, Ultimap 2, better hotkeys, more programming options, and more(See below). Download: Cheat Engine 6.6 If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker, irc or by e-mail. And if you have questions, don't hesitate to ask them in the forum or irc Fixes: Fixed saving of hotkey sounds Fixed the CF flag in the disassembler stepping mode Fixed Kernelmode VirtualQueryEx for Windows 10 build 14393 Fixed DBVM for Windows 10 build 14393 Fixed the shortest assembler instruction picking for some instructions Fixed a few bugs in the break and trace routine when you'd stop it while the thread still had a single step set Fixed several ansi to UTF8 incompatbilities that poped up between 6.5 and 6.5.1 Fixed the stackview not properly setting the color, and giving an error when trying to change a color Fixed the exe generator not adding both .sys files or the .sig files when using kernel functions Fixed some places of the disassembler where it helps guessing if something is a float or not When using the code finder, it won't show the previous instruction anymore if it's on a REP MOVS* instruction Fixed an issue when editing memoryrecords with strings, where wordwrap would add newline characters Fixed D3D alpha channel for textures and fontmaps Fixed the helpfile not being searchable The installer will now mark the CE destination folder as accessible by APPS. (fixes speedhack for some APPS) Fixed the form designed crashing is resized 'wrong' Additions and changes: Ultimap 2 for Intel CPU's of generation 6 and later (no DBVM needed for those) Language select if you have multiple language files for CE Memoryrecord pointer offsets can use calculations, symbols and lua code now While stepping in the debugger you can now easily change the EIP/RIP register by pressing ctrl+f4 changed the way CE is brought to front when a hotkey is pressed Made the GUI more adaptive to different fontsizes and DPI Several font and minor GUI changes Added DPIAware and a font override to the settings window. (DPI aware is on by default, but can be turned of if experiencing issues) Added option to enable pause by default Disassembling mega jumps/calls now show the code in one line The standalone auto assembler window will now give an option to go to the first allocated memory address Changed the point where the settings are loaded in CE's startup sequence The formdesigner now allows copy and paste of multiple objects, and uses text Added scrollbox and radiogroup to the formdesigner Added Middle, MB4 and MB5 as allowable hotkeys Added controller keys as hotkeys Single stepping now shows an indication if an condition jump will be taken Added a watchlist to the debugger Added the 'align' assembler pseudo command (allocates memory so the next line is aligned on a block of the required size) Added the 'Not' option for scans, which causes all addresses that match the given entry as invalid Changed the Unicode text to UTF-16. Text scans are now UTF8/UTF16 (no codepage) Hexview can now show and edit values in 3 different textencodings. (Ascii, UTF-8 and UTF-16) Rescan pointerscans on pointerscans that where done on a range can now change the offset lua: speak(): Text to speech hookWndProc: a function that lets you hook the windows message handler of a window registerEXETrainerFeature: Lets you add extra files to the exe trainer file packer getFileVersion(): A function to get version information from a file mouse_event() : Lets you send mouse events to windows. (move, click, etc...) loadFontFromStream() : Lets you load a font from a memory stream. (Useful for trainers that use a custom font) added several thread synchronization objects control class: added bringToFront and sendToBack lua changes: dbk_writesIgnoreWriteProtection() now also disables virtualprotectex calls from CE loadTable() can now also load from a Stream object. the addresslist has some Color properties published for better customization the LUA server has had some new commands added so hooked code can do more efficient calls. (LUAClient dll has been updated to use them in a basic way) Russian translation has been updated French tutorial only translation has been updated as well 10/10/2016:6.6.0.1: Fixed align May 19 2016:Cheat Engine 6.5.1 Released: 6.5.1 has been released. It's mainly a bugfix version to replace 6.5 which had a few minor bugs that needed solving. Download: Cheat Engine 6.5.1 Fixes: Fixed increased value by/decreased value by for float values Fixed disassembling/assembling some instructions (64-bit) Fixed the autoassembler tokenizing wrong words Fixed several bugs related to the structure dissect window (mainly shown when autodestroy was on) Fixed a small saving issue Groupscans now deal with alignment issues better Fixed java support for 32-bit Additions and changes: Signed with a sha256 signature as well (for OS'es that support it) Changed Ultimap to use an official way to get the perfmon interrupt instead of IDT hooking (less BSOD on win10 and 8) Individual hotkeys can now play sounds Now compiled with fpc 3.0/lazarus 1.6 (Previously 2.7/1.1) You can now search in the string list PEInfo now has a copy to clipboard Some places can now deal better with mistakes Lazarus .LFM files can now be loaded and saved lua: Fixed several incompatibilities between lua that popped up in 6.5 (due to the lua 5.1 to 5.3 change) Fixed the OnSelectionChange callback property in the memoryview object MemoryRecords now have an Collapsed property Added TCanResizeEvent to the splitter Fixed setBreakpoint not setting a proper trigger if not provided Fixed executeCode* parameter passing Fixed several memory leaks where unregistering hooks/addons didn't free the internal call object Some tableFile additions Fixed registerAssemble assembler commands Added kernelmode alloc and (un)mapping functionality Added an easy way to add auto assembler templates Added window related functions including sendMessage Added Xbox360 controller support functions Added more thread functions Post release fixes: Dealt with several gui issues like the mainform to front on modal dialogs, header resizing stuck with the cursor, treeview item selection/deletion being weird, etc... Added a disconnect to the client in pointerscans Fixed pointerscan issue with 32-bit aligned pointers in a 64-bit process Fixed a deadlock in threads when lua custom types where used Post release fixes: Dealt with several gui issues like the mainform to front on modal dialogs, header resizing stuck with the cursor, treeview item selection/deletion being weird, etc... Added a disconnect to the client in pointerscans fixed pointerscan issue with 32-bit aligned pointers in a 64-bit process Fixed a deadlock in threads when lua custom types where used Fixed pointerscan resume 6/1/2016: (major bugfix) properly fixed resume of pointerscans and alignment fix December 31 2015:Cheat Engine 6.5 Released: I'd like to announce the release of Cheat Engine 6.5 If you encounter bugs or have suggestions, please do not hesitate to report them in the forum, bugtracker, irc or by e-mail. And if you have questions, don't hesitate to ask them in the forum or irc Fixes: Fixed page exception breakpoints from not working Fixed the save as button in the lua script assigned to the table Fixed the dotnetdatacollector from not fetching parent fields Fixed disassembling of some instructions Fixed assembling some instructions Fixed assembling instructions that referenced address 80000000 to ffffffff in 64-bit targets Fixed dealing with unexpected breakpoints Fixed several issues with the network scanner. (symbols, scanspeed, threads, etc...) Fixed "going to" 64-bit registers. Fixed pointerstrings for 64-bit Fixed the addressparser in memview's hexview not handing static 64-bit addresses Fixed r8 and r9 looking broken in the memoryview window Fixed hotkeys that set a value as hexadecimal and the value is smaller than 0x10 Fixed multiline string editing for memory records Fixed dragging cheat tables into CE Fixed VEH debug for 'Modern' apps Fixed several translation issues lua: fixed getStructureCount, writeRegionToFile, readRegionFromFile, readInteger, ListColum.GetCount fixed memoryleak in MemoryStream Several fixes to DBVM: added support for Windows 10 support for more than 8 cpu's support for newer cpu's fixed issue where calling CPUID right after setting the TF flag wouldn't trigger a breakpoint after it Additions and changes: Array of Byte's can now deal with nibble's. (e.g: 9* *0 90 is now a valid input- and scanstring) The auto assembler can now deal with some mistakes like forgetting to declare a label Added support to use binutils as assembler and disassembler, and a special scripting language for it Added support for 64-bit mono, and script support for cases where mono.dll isn't called mono.dll Added an option to get a list of all recently accessed memory regions. This is useful for the pointerscanner The pointerscanner can now use multiple snapshots (pointermaps) to do a scan. This basically lets you do a rescan during the first scan, saving your harddisk Made the pointerscan network scanner a bit easier to use. You can now join and leave a pointerscan session You can now stop pointerscans and resume them at a later time Pointerscan files can get converted to and from sqlite database files The pointerscan configuration window now has an advanced and basic mode display The all type now has a setting that lets you define what under "all" falls Custom types now also have access to the address they're being used on Split up the "(de)activating this (de)activates children" into two seperate options (one for activate, one for deactivate) Added some basic Thumb disassembling The xmplayer has been replaced with mikmod which supports many different module types (in lua you still call it xmplayer) Rightlicking on "your system supports dbvm" will let you manually load DBVM for each cpu. This is usefull if for some reason your system crashes when it's done too quickly In "Find what addresses this instruction accesses" you can now open the structure dissect window of your choice in case there are others. It will also fill in the base address, so no need to recalculate yourself AA command GlobalAlloc now has an optional 3th parameter that lets you specify the prefered region Added an option to record and undo writes. (Off by default, can be enabled in settings. Memview ctrl+z will undo the last edit) Added aobscanregion(name,startaddress,stopaddress,aob) lua: switched from Lua 5.1 to 5.3 debug_setBreakpoint can now take an OnBreakpoint parameter that lets you set a specific function just for that breakpoint added dbk_getPhysicalAddress(int) added dbk_writesIgnoreWriteProtection(bool) added getWindowList() And a bunch of other lua functions. (check out main.lua) Post release fixes (max 7 days after initial release *or 30 if a HUGE bug): 1/6/2016:Fixed structure dissect from crashing when autodestroy is on 1/6/2016:Fixed window position loading on multi monitor systems 1/6/2016:Fixed the lua customtype and 1/6/2016:Several minor gui fixe
6 , chunks.zip<br>This will open a file and read it in "Chunks" of a selected file.<END><br>7 , logging.zip<br>This is a bas that will log installation procedures so the file can be removed later.<END><br>8 , savetree.zip<br>This will save the info in a Tree View. "This technique allows a program to save hierarchical information like the data in a TreeView in a way that is easy to understand."<END><br>11 , OLE.zip<br>Demonstrates the use of OLE.<END><br>12 , gradtxt2.zip<br>"A program for drawing horizontal, rectangular or spherical gradient texts."<END><br>13 , sweepgl.zip<br>This example greatly demonstrates how to use OpenGL in Visual Basic.<END><br>15 , drawdemo.zip<br>This is an excellent example of how to make a paint program with a few extras.<END><br>16 , cube.zip<br>This example demonstrates how to rotate a cube in visual basic.<END><br>17 , sprite1.zip<br>This is an Excellent example on how to use sprites in your program.<END><br>18 , charcreate.zip<br>This is an example of how to assign "characters" to differant pictureboxes. This would be a good starting point for VB game developers.<END><br>19 , breakthrough.zip<br>This demonstrates a simple game in Visual Basic. An excellent example.<END><br>26 , openlib.zip<br>These are the type libs that go with OpenGL. This is used to make 3D text.<END><br>27 , basMath.zip<br>This module contains functions for various math equations. <END><br>28 , calc.zip<br>This is a basic calculator written in Visual Basic.<END><br>29 , stopwatch.zip<br>This shows how to count off time in a Stop Watch format.<END><br>31 , taskhide.zip<br>This will hide your application from the taskbar, Alt+Tab, and Alt+Ctrl+Del.<END><br>32 , newbie.zip<br>This is a nicely done help file for programmers that are new to Visual Basic.<END><br>33 , vbfaq.zip<br>This is AOL's PC Dev Visual Basic FAQ. This is an excellent starting point for begginners.<END><br>34 , Bas.zip<br>it is very good modual for activex<END><br>35, paraviasource.zip<br>This is

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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