当前位置: 技术问答>linux和unix
自己在看KDevelop生成的代码,写了点笔记,希望高手给看看那里有错误,
来源: 互联网 发布时间:2015-11-02
本文导语: 请大家纠正拍砖,要是能把自己的学习经验或其他所由有用的提出来就更好了 先使劲谢谢 KDevelop学习笔记一(测试,希望大家闲了,帮我看下,我翻译英文部分哪里不对) 在网上找了好久 都没有看到KDevelop的资料 大家的建...
请大家纠正拍砖,要是能把自己的学习经验或其他所由有用的提出来就更好了
先使劲谢谢
KDevelop学习笔记一(测试,希望大家闲了,帮我看下,我翻译英文部分哪里不对)
在网上找了好久
都没有看到KDevelop的资料
大家的建议都是直接看他自带的文档,恩,一个类似MSDN的东西
内容太多,算了,我直接看他生成的代码吧
KDevelop跟VC十分的像,www.Linuxc.net的老大说这个就是照VC开发的,还好,VC对我不是问题
找到叫"工程"的菜单新建个工程先
wizard出来了,在目录c++里的KDE里找到头一个application framework,多年经验告诉我,这是最基础的之一.
我将"Generates a simple KDE application with one toplevel window, menus and toolbars. A DCOP interface is also provided, so that your application can provide a scripting interface"
我起的工程名是KDE
然后完成其他的下一步下一步,工程终于搞出来了
build出来后~~恩,确实跟VC里的SDI很像~
点开左边的类view有6个类,KDEApp,KDEAppIface,KDEAppPreferences,KDEAppPrefPageOne,KDEAppPrefPageTwo,KDEAppView
还有两个main
奇怪,两个~~~
还有3个全局变量
表面上看KDEApp是App类,还有一个View类KDEAppView,没有Doc类,估计跟MFC中的"文档/视图"(这种概念简单的讲就是视图负责显示,文档负责数据)的概念一样
再看下文件夹,东西不少,其中有个src,
里面装着我要看的(去掉了一些我现在认为没必要的文件包括makefile)
kdeapp.h kdeapp.cpp kdeappview.h kdeappview.cpp kdeapp_client.cpp kdeappiface.h pref.cpp main.cpp pref.h
侦查的差不多了,看看两个main到底是怎么回事吧,
一个在kdeapp_client.cpp里一个在main.cpp里
main.cpp中的main一开始就是KAboutData about...
估计他是菜单里的about,
重点放在kdeapp_client.cpp里
要想知道他是如何工作的就要跟他
先下上断点,对了这里叫切换断点
奇怪怎么在kdeapp_client.cpp里的main中的断点没有执行到?
看来前面的判断有问题,索性看看堆栈是怎么样的
在两个main开头都设了断点,开始调试
停在了main.cpp中的main里
再看堆栈,就他一个函数,看来这里是入口
KAboutData about...
该看文档了,在右边的文档里一查
KAboutData Class Reference
This class is used to store information about a program.Holds information needed by the "About" box and other classes
是用来放程序信息的,看来不能光望文生义了
下面是main.cpp中的主要代码
int main(int argc, char **argv)
{
KAboutData about("kdeapp", I18N_NOOP("KDEApp"), version, description,
KAboutData::License_GPL, "(C) 2005 snail", 0, 0, "snail@localhost.localdomain");
about.addAuthor( "snail", 0, "snail@localhost.localdomain" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
KApplication app;
// register ourselves as a dcop client
app.dcopClient()->registerAs(app.name(), false);
// see if we are starting with session management
if (app.isRestored())
{
RESTORE(KDEApp);
}
else
{
// no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->count() == 0)
{
KDEApp *widget = new KDEApp;
widget->show();
}
else
{
int i = 0;
for (; i count(); i++)
{
KDEApp *widget = new KDEApp;
widget->show();
widget->load(args->url(/tech-qa-linux/i/index.html));
}
}
args->clear();
}
return app.exec();
}
接着将一段段的看
————————————————————————————————————————————
KAboutData about("kdeapp", I18N_NOOP("KDEApp"), version, description,
KAboutData::License_GPL, "(C) 2005 snail", 0, 0, "snail@localhost.localdomain");
about.addAuthor( "snail", 0, "snail@localhost.localdomain" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
————————————————————————————————————————————
about.addAuthor( "snail", 0, "snail@localhost.localdomain" );
很显然,添加作者,安全期间我看下文档好了“Defines an author.”看来没猜错
KCmdLineArgs
A class for command-line argument handling.
KCmdLineArgs provides simple access to the command-line arguments for an application. It takes into account Qt-specific options, KDE-specific options and application specific options.
This class is used in main() via the static method init().
这个类是管理命令行选项的
void KCmdLineArgs::init ( int _argc,
char ** _argv,
const KAboutData * about,
bool noKApp = false
)
Initialize class.
This function should be called as the very first thing in your application. It uses KAboutData to replace some of the arguments that would otherwise be required.
通过把KAboutData对象的信息传进去init
void KCmdLineArgs::addCmdLineOptions ( const KCmdLineOptions * options,
const char * name = 0,
const char * id = 0,
const char * afterId = 0
)
Add options to your application.
要加的选项是一个全局变量option定义是如下
static KCmdLineOptions options[] =
{
{ "+[URL]", I18N_NOOP( "Document to open" ), 0 },
KCmdLineLastOption
};
KCmdLineOptions
Structure that holds command line options.
This class is intended to be used with the KCmdLineArgs class, which provides convenient and powerful command line argument parsing and handling functionality.
是个存放命令行选项的类,属性有
const char * name
const char * description
const char * def
分别是
The name of the argument as it should be called on the command line and appear in myapp --help.
选项的名字
The text description of the option as should appear in myapp --help.
选项的描述
The default value for the option, if it is not specified on the command line.
选项的缺省值
这里还有一个宏
#define I18N_NOOP(x) x
I18N_NOOP marks a string to be translated without translating it. Do not use this unless you know you need it.
标记一个要被翻译的字符串,还有一个宏
#define I18N_NOOP2(comment, x) x
If the string is too ambiguous to be translated well to a non-english language, use this instead of I18N_NOOP to separate lookup string and english.
Warning:
You need to call i18n( comment, stringVar ) later on, not just i18n( stringVar ).
看解释是有多种意思的时候用这个,怎么用,用到哪我还不清楚
————————————————————————————————————————————————
KApplication app;
// register ourselves as a dcop client
app.dcopClient()->registerAs(app.name(), false);
————————————————————————————————————————————————
KApplication
Controls and provides information to all KDE applications.
Only one object of this class can be instantiated in a single app. This instance is always accessible via the 'kapp' global variable.
控制整个程序的类,只能实例化一次在一个程序中,看来我们不用太关心他,起码刚开始学的时候
后面又注释了,将自己注册成dcop客户端,dcop??
DCOPClient * KApplication::dcopClient()
Returns a pointer to a DCOPClient for the application.
If a client does not exist yet, it is created when this function is called.
DCOPClient是什么?查查看
Inter-process communication and remote procedure calls for KDE applications.
为KDE程序提供内部进程通信和远程过程调用
registerAs(app.name(), false)
DCOPClient::registerAs ( const QCString & appId, bool addPID = true )
Registers at the DCOP server.
在dcop server上注册自己,addPID为什么是false呢?
appId is a unique application/program id that the server will use to associate requests with. If there is already an application registered with the same name, the server will add a number to the id to unify it. If addPID is true, the PID of the current process will be added to id.
appId是用来区分每个进程的ID,false就是他不注册这个ID到dcop server上了~~
先使劲谢谢
KDevelop学习笔记一(测试,希望大家闲了,帮我看下,我翻译英文部分哪里不对)
在网上找了好久
都没有看到KDevelop的资料
大家的建议都是直接看他自带的文档,恩,一个类似MSDN的东西
内容太多,算了,我直接看他生成的代码吧
KDevelop跟VC十分的像,www.Linuxc.net的老大说这个就是照VC开发的,还好,VC对我不是问题
找到叫"工程"的菜单新建个工程先
wizard出来了,在目录c++里的KDE里找到头一个application framework,多年经验告诉我,这是最基础的之一.
我将"Generates a simple KDE application with one toplevel window, menus and toolbars. A DCOP interface is also provided, so that your application can provide a scripting interface"
我起的工程名是KDE
然后完成其他的下一步下一步,工程终于搞出来了
build出来后~~恩,确实跟VC里的SDI很像~
点开左边的类view有6个类,KDEApp,KDEAppIface,KDEAppPreferences,KDEAppPrefPageOne,KDEAppPrefPageTwo,KDEAppView
还有两个main
奇怪,两个~~~
还有3个全局变量
表面上看KDEApp是App类,还有一个View类KDEAppView,没有Doc类,估计跟MFC中的"文档/视图"(这种概念简单的讲就是视图负责显示,文档负责数据)的概念一样
再看下文件夹,东西不少,其中有个src,
里面装着我要看的(去掉了一些我现在认为没必要的文件包括makefile)
kdeapp.h kdeapp.cpp kdeappview.h kdeappview.cpp kdeapp_client.cpp kdeappiface.h pref.cpp main.cpp pref.h
侦查的差不多了,看看两个main到底是怎么回事吧,
一个在kdeapp_client.cpp里一个在main.cpp里
main.cpp中的main一开始就是KAboutData about...
估计他是菜单里的about,
重点放在kdeapp_client.cpp里
要想知道他是如何工作的就要跟他
先下上断点,对了这里叫切换断点
奇怪怎么在kdeapp_client.cpp里的main中的断点没有执行到?
看来前面的判断有问题,索性看看堆栈是怎么样的
在两个main开头都设了断点,开始调试
停在了main.cpp中的main里
再看堆栈,就他一个函数,看来这里是入口
KAboutData about...
该看文档了,在右边的文档里一查
KAboutData Class Reference
This class is used to store information about a program.Holds information needed by the "About" box and other classes
是用来放程序信息的,看来不能光望文生义了
下面是main.cpp中的主要代码
int main(int argc, char **argv)
{
KAboutData about("kdeapp", I18N_NOOP("KDEApp"), version, description,
KAboutData::License_GPL, "(C) 2005 snail", 0, 0, "snail@localhost.localdomain");
about.addAuthor( "snail", 0, "snail@localhost.localdomain" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
KApplication app;
// register ourselves as a dcop client
app.dcopClient()->registerAs(app.name(), false);
// see if we are starting with session management
if (app.isRestored())
{
RESTORE(KDEApp);
}
else
{
// no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->count() == 0)
{
KDEApp *widget = new KDEApp;
widget->show();
}
else
{
int i = 0;
for (; i count(); i++)
{
KDEApp *widget = new KDEApp;
widget->show();
widget->load(args->url(/tech-qa-linux/i/index.html));
}
}
args->clear();
}
return app.exec();
}
接着将一段段的看
————————————————————————————————————————————
KAboutData about("kdeapp", I18N_NOOP("KDEApp"), version, description,
KAboutData::License_GPL, "(C) 2005 snail", 0, 0, "snail@localhost.localdomain");
about.addAuthor( "snail", 0, "snail@localhost.localdomain" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
————————————————————————————————————————————
about.addAuthor( "snail", 0, "snail@localhost.localdomain" );
很显然,添加作者,安全期间我看下文档好了“Defines an author.”看来没猜错
KCmdLineArgs
A class for command-line argument handling.
KCmdLineArgs provides simple access to the command-line arguments for an application. It takes into account Qt-specific options, KDE-specific options and application specific options.
This class is used in main() via the static method init().
这个类是管理命令行选项的
void KCmdLineArgs::init ( int _argc,
char ** _argv,
const KAboutData * about,
bool noKApp = false
)
Initialize class.
This function should be called as the very first thing in your application. It uses KAboutData to replace some of the arguments that would otherwise be required.
通过把KAboutData对象的信息传进去init
void KCmdLineArgs::addCmdLineOptions ( const KCmdLineOptions * options,
const char * name = 0,
const char * id = 0,
const char * afterId = 0
)
Add options to your application.
要加的选项是一个全局变量option定义是如下
static KCmdLineOptions options[] =
{
{ "+[URL]", I18N_NOOP( "Document to open" ), 0 },
KCmdLineLastOption
};
KCmdLineOptions
Structure that holds command line options.
This class is intended to be used with the KCmdLineArgs class, which provides convenient and powerful command line argument parsing and handling functionality.
是个存放命令行选项的类,属性有
const char * name
const char * description
const char * def
分别是
The name of the argument as it should be called on the command line and appear in myapp --help.
选项的名字
The text description of the option as should appear in myapp --help.
选项的描述
The default value for the option, if it is not specified on the command line.
选项的缺省值
这里还有一个宏
#define I18N_NOOP(x) x
I18N_NOOP marks a string to be translated without translating it. Do not use this unless you know you need it.
标记一个要被翻译的字符串,还有一个宏
#define I18N_NOOP2(comment, x) x
If the string is too ambiguous to be translated well to a non-english language, use this instead of I18N_NOOP to separate lookup string and english.
Warning:
You need to call i18n( comment, stringVar ) later on, not just i18n( stringVar ).
看解释是有多种意思的时候用这个,怎么用,用到哪我还不清楚
————————————————————————————————————————————————
KApplication app;
// register ourselves as a dcop client
app.dcopClient()->registerAs(app.name(), false);
————————————————————————————————————————————————
KApplication
Controls and provides information to all KDE applications.
Only one object of this class can be instantiated in a single app. This instance is always accessible via the 'kapp' global variable.
控制整个程序的类,只能实例化一次在一个程序中,看来我们不用太关心他,起码刚开始学的时候
后面又注释了,将自己注册成dcop客户端,dcop??
DCOPClient * KApplication::dcopClient()
Returns a pointer to a DCOPClient for the application.
If a client does not exist yet, it is created when this function is called.
DCOPClient是什么?查查看
Inter-process communication and remote procedure calls for KDE applications.
为KDE程序提供内部进程通信和远程过程调用
registerAs(app.name(), false)
DCOPClient::registerAs ( const QCString & appId, bool addPID = true )
Registers at the DCOP server.
在dcop server上注册自己,addPID为什么是false呢?
appId is a unique application/program id that the server will use to associate requests with. If there is already an application registered with the same name, the server will add a number to the id to unify it. If addPID is true, the PID of the current process will be added to id.
appId是用来区分每个进程的ID,false就是他不注册这个ID到dcop server上了~~
|
我觉得学东西还是要学其根本。KDE只是在QT之上封装了很薄的一层。
还是应该从QT文档和QT应用开始,从最基本的地方入手。QT文档里列举了QT的几大基本特性,特别是slot-signal。完全明白这些,才能写出好的KDE/QT应用。
还是应该从QT文档和QT应用开始,从最基本的地方入手。QT文档里列举了QT的几大基本特性,特别是slot-signal。完全明白这些,才能写出好的KDE/QT应用。
|
你可以再试一下用KDevelop编一个QT程序,应该比KDE程序更清晰一些, 更容易搞懂KDE程序的本质.
QT的话,例子非常多, 文档也是很丰富的. 等熟练掌握QT之后回头再来研究KDE程序就可以比较容易抓住KDE相关的内容了.
QT的话,例子非常多, 文档也是很丰富的. 等熟练掌握QT之后回头再来研究KDE程序就可以比较容易抓住KDE相关的内容了.