Beginning Linux Programming 学习--chapter 17 Programming KDE using QT
KDE:
KDE,K桌面环境(K Desktop Environment)的缩写。一种著名的运行于 Linux、Unix 以及FreeBSD 等操作系统上的自由图形桌面环境,整个系统采用的都是 TrollTech 公司所开发的Qt程序库(现在属于Digia公司)。KDE Linux 操作系统上最流行的桌面环境之一。K桌面项目始建于1996年, K桌面项目是由图形排版工具Lyx的开发者, 名为Matthias Ettrich的德国人发起的,目的是为满足普通用户也能够通过简单易用的桌面来管理Unix工作站上的各种应用软件以及完成各种任务。是开源的!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在linux系统系统中安装qt的方法
1): 直接用rpm包
2): 下载源码,自己编译;自己编译之后,需要注意:
a) make sure the lib directory of QT is added to /etc/ld.so.conf 文件。方法是在该文件中写入入qt lib的目录,例如"/usr /lib/qt-3.3/lib",具体跟自己安装的路径有关,可以添加到该文件中的任意位置。 另外,On Fedora and Red Hat Linux systems, the line should be stored in /etc/ld.so.conf.d/qt-i386.conf 。 添加之后,还需要运行一条指令# ldconfig ,需要root权限。
b)When Qt is properly installed, the QTDIR environment variable(环境变量) should be set to the Qt installation directory. You can check that this is the case as follows: ------如何设置这个环境变量的值??
$ echo $QTDIR
其他:ld.so.conf 和ldconfig是维护系统动态链接库的。当前的Linux大多是将函数库做成动态函数库,内存的访问速度是硬盘的好几倍,所以,如果将常用的动态函数库加载到内存中(高速缓存,cache),当软件套件要采用动态函数库时,就不需要重新从硬盘里读出,这样就可以提高动态函数库的读取速度。这个时候需要ldconfig与 /etc/ld.so.conf的帮助。 https://blog.csdn.net/fangquan1980/article/details/49363173
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
书中,写了一个C++文件来显示一个主窗口,直接用g++进行了编译:
$ g++ -o qt1 qt1.cpp –I$QTDIR/include –L$QTDIR/lib –lqui ($QTDIR 是环境变量)(-lxxx应该就是表示加上xxx库)
我知道 -lqui,应该是包含qui库,但是不知道g++的这种用法的格式???
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
每一个qt程序中必须要有,而且只能有一个class QApplication的对象! QApplication deals with underthe-hood Qt operations such as event handling, string localization, and controlling the look and feel.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
信号和槽:
As you saw in Chapter 16, signals and signal handling are the primary mechanisms a GUI application
uses to respond to user input and are central features of all GUI libraries.(qt,mfc都是一种gui 库 )。Qt is a C++ library that uses a signal/slot mechanism to implement event-driven programming.
Qt定义了两个关键字:signal , slots,来指明信号和槽函数,着对于代码的可读性和维护行非常好,但是这两个关键字不是C++的关键字,而Qt又是一个c++库,从而,qt的代码需要被处理,将代码中的signal和slots关键子用C++代码替换!
Qt code, therefore, is not true C++ code. This has sometimes been an issue for some developers. See
http://doc.trolltech.com/ for Qt documentation, including reasons for these new pseudo C++
keywords. Furthermore, the use of signals and slots does not differ all that much from the Microsoft
Foundation Classes, or MFC, on Windows, which also uses a modified definition of the C++ language
qt中信号和槽使用的限制:There are some restrictions to how signals and slots can be used in Qt, but these are not significantly limiting:
❑ Signals and slots must be member functions of a class derived from QObject.
❑ If using multiple inheritance, QObject must appear first in the class list.
❑ A Q_OBJECT statement must appear in the class declaration.一般放在类定义中的第一行,下面是构造函数。
❑ Signals cannot be used in templates.
❑ Function pointers cannot be used as arguments to signals and slots.---没有体会过
❑ Signals and slots cannot be overridden and upgraded to public status(??).
connnect函数是QObject类的静态函数:--(qt4的例子)
To use slots, you must connect them to a signal. You do this with the appropriately named static connect method in the QObject class:
bool QObject::connect (const QObject * sender, const char * signal, const QObject * receiver, const char * member)
In the MyWindow example, if you wanted to connect the clicked signal of a QPushButton widget to
your doSomething slot, you’d write
connect ( button, SIGNAL(clicked()), this, SLOT( doSomething() ) );
Note that you must use SIGNAL and SLOT macros to surround the signal and slot functions. Just as in
GTK+, you can connect any number of slots to a given signal and also connect a slot to any number of
signals by multiple connect calls. If connect fails for any reason, it returns FALSE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
书中关于信号和槽函数的一个例子:(qt4), 关键看它是怎么用g++进行编译的!
1. ButtonWindow.h文件:
#include <qmainwindow.h>
class ButtonWindow : public QMainWindow
{
Q_OBJECT
public:
ButtonWindow(QWidget *parent = 0, const char *name = 0);
virtual ~ButtonWindow();
private slots:
void Clicked();
};
2. ButtonWindow.cpp文件:
#include “ButtonWindow.moc”
#include <qpushbutton.h>
#include <qapplication.h>
#include <iostream>
// In the constructor, you set the window title, create the button, and connect the button’s clicked //signal to your slot. setCaption is a QMainWindow method that unsurprisingly sets the window title.
ButtonWindow::ButtonWindow(QWidget *parent, const char *name): QMainWindow(parent, name)
{
this->setCaption(“This is the window Title”);
QPushButton *button = new QPushButton(“Click Me!”, this, “Button1”);
button->setGeometry(50,30,70,20);
connect (button, SIGNAL(clicked()), this, SLOT(Clicked()));
}
//Qt manages the destruction of widgets automatically, so your destructor is empty:
ButtonWindow::~ButtonWindow()
{}
void ButtonWindow::Clicked(void)
{
std::cout << “clicked!\n”;
}
int main(int argc, char **argv)
{
QApplication app(argc,argv);
ButtonWindow *window = new ButtonWindow();
app.setMainWidget(window);//set it as your application’s main window
window->show();
return app.exec();
}
编译:--需要先使用元对象编译器(meta object compiler)对头文件进行处理!应该是在将qt自己定义的一些关键字,替换为标准的C++代码!!!!!!!
Before you can compile this example, you need to run the preprocessor on the header file. This
preprocessor program is called the Meta Object Compiler (moc) and should be present in the
Qt package. Run moc on ButtonWindow.h, saving the output as ButtonWindow.moc:
$ moc ButtonWindow.h –o ButtonWindow.moc
Now you can compile as usual, linking in the moc output:
$ g++ -o button ButtonWindow.cpp –I$QTDIR/include –L$QTDIR/lib –lqui
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QT中布局控件位置的方法,自动适应窗口大小的方法:---qt4
There are a number of ways to arrange the positioning and layout of widgets in Qt. You’ve already seen using absolute coordinates by calling setGeometry, but this is rarely used, because the widgets don’t scale and adjust to fit the window if it is resized.
The preferred method of arranging widgets is by using the QLayout classes or box widgets, which intelligently resize, after you’ve given them hints on margins and spacing between widgets.
QLayout classes 与box widgets的区别:
The key difference between the QLayout classes and box widgets is that layout objects are not widgets. The layout classes derive from QObject and not Qwidget, so you are constrained in how you can use them. You cannot, for instance, make a QVBoxLayout a central widget of a QMainWindow.
Box widgets (such as QHBox and QVBox), by contrast, are derived from QWidget, and therefore you can treat them as ordinary widgets.
You might well wonder why Qt has both QLayouts and QBox widgets with duplicate functionality. Actually QBox widgets are just for convenience, and in essence wrap a QLayout within a QWidget. QLayouts have the advantage of automatically resizing, whereas widgets must be manually resized by calling QWidget::resizeEvent().
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QLaycout类的详细介绍:
The QLayout subclasses QVBoxLayout and QHBoxLayout are the most popular way of creating an interface, and the ones you will most often see in Qt code.
QVBoxLayout and QHBoxLayout are invisible container objects that hold other widgets and layouts in
a vertical and a horizontal orientation, respectively. You can create arbitrarily complex arrangements of widgets because you can nest layouts by placing a horizontal layout as an element inside a vertical layout, for example.
QVBoxLayout 类的三个构造函数: (QHBoxLayout has an identical API):
QVBoxLayout::QVBoxLayout (QWidget *parent, int margin, int spacing, const char*name)
QVBoxLayout::QVBoxLayout (QLayout *parentLayout, int spacing, const char * name)
QVBoxLayout::QVBoxLayout (int spacing, const char *name)
The parent of the QLayout can be either a widget or another QLayout. If you specify no parent, you can only add the layout to another QLayout later, using the addLayout method.
margin and spacing set the empty space in pixels placed around the outside of the QLayout and in between individual widgets.
Once you've created your QLayout, you add child widgets or layouts using a couple of methods:
QBoxLayout::addWidget (QWidget *widget, int stretch = 0, int alignment = 0 )
QBoxLayout::addLayout (QLayout *layout, int stretch = 0)
QLaycout类的使用例子:--还没看
---后面的都是介绍的qt的各种控件的使用方法了!
Beginning Linux Programming 学习--chapter 17 Programming KDE using QT的更多相关文章
- Beginning Linux Programming 学习--chapter 11 Processes and Signals
What's process--什么是进程? The UNIX standards, specifically IEEE Std 1003.1, 2004 Edition, defines a pr ...
- Beginning Linux Programming 学习--chapter 1 Getting start--What's linux,GNU,HeaderFiles, Libraries
"文明的建立的不是机器而是思想" -- 托尔斯泰 Linux truly become a viable operating system, especially in the s ...
- Linux命令学习(17):ifconfig命令
版权声明更新:2017-05-22博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 我们知道,在windows中,除了在图形界 ...
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
- Linux Basic学习笔记01
介绍课程: 中级: 初级:系统基础 中级:系统管理.服务安全及服务管理.Shell脚本: 高级: MySQL数据库: cache & storage 集群: Cluster lb: 4laye ...
- Linux.NET学习手记(7)
前一篇中,我们简单的讲述了下如何在Linux.NET中部署第一个ASP.NET MVC 5.0的程序.而目前微软已经提出OWIN并致力于发展VNext,接下来系列中,我们将会向OWIN方向转战. 早在 ...
- 别出心裁的Linux系统调用学习法
别出心裁的Linux系统调用学习法 操作系统与系统调用 操作系统(Operating System,简称OS)是计算机中最重要的系统软件,是这样的一组系统程序的集成:这些系统程序在用户对计算机的使用中 ...
- Linux驱动学习步骤(转载)
1. 学会写简单的makefile 2. 编一应用程序,可以用makefile跑起来 3. 学会写驱动的makefile 4. 写一简单char驱动,makefile编译通过,可以insmod, ls ...
- 关于Linux内核学习的误区以及相关书籍介绍
http://www.hzlitai.com.cn/article/ARM9-article/system/1605.html 写给Linux内核新手-关于Linux内核学习的误区 先说句正经的:其实 ...
随机推荐
- NAT端口映射综合详解
- Spring boot 事务Transactional
开启事务只需要加上注解@Transactional即可 // 默认情况下数据库的事务作用范围是在JapRepository 的crud上 // save 一旦执行成功,就会进行提交 // 开启事务后遇 ...
- 蛋疼的springboot web项目使用jetty容器运行
出现的问题: 今天自己新建了一个maven webapp项目,准备自己看看springboot的东西,搭好的项目是这样的 一切都很正常啊,用run App的方式直接启动 成功啦,本应该到此结束,喝茶吃 ...
- Leet Code 2.两数相加
2.两数相加 题目描述 给出两个非空的链表用来表示两个非负的整数.其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只能存储一位数字.如果,我们将这两个数相加起来,则会返回一个新的链表来表 ...
- 第2课第2节_Java面向对象编程_封装性_P【学习笔记】
摘要:韦东山android视频学习笔记 面向对象程序的三大特性之封装性:把属性和方法封装在一个整体,同时添加权限访问. 1.封装性的简单程序如下,看一下第19行,如果我们不对age变量进行权限的管控 ...
- 阿里物联网平台(一)Windows系统+VS2017 模拟设备端接入
https://blog.csdn.net/panwen1111/article/details/88365636 一.阿里物联网平台 平台地址:https://account.aliyun.com ...
- PHP 构造函数和析构函数
构造函数 __construct ([ mixed $args [, $... ]] ) : void PHP 5 允行开发者在一个类中定义一个方法作为构造函数.具有构造函数的类会在每次创建新对象时先 ...
- ubuntu 防火墙打开关闭
1.查看防火墙状态 sudo ufw status 2.打开防火墙 sudo ufw enable 3.关闭防火墙 sudo ufw disable
- 【微信开发】微信小程序通过经纬度计算两地距离php代码实现
需求: 要求做个根据用户当前位置获取周围商家地址,并且按照由近到远排序, 方法一: 代码层实现 封装方法: /** * @desc 根据两点间的经纬度计算距离 * @param float $lat ...
- 【438】Python 处理文件
1. 读取文件,计算 tweets 数目 python中readline判断文件读取结束的方法 line == '' python:如何检查一行是否为空行 line == '\n' or line = ...