自己在看KDevelop生成的代码,写了点笔记,希望高手给看看那里有错误,

thisisll 2005-12-13 09:31:01
请大家纠正拍砖,要是能把自己的学习经验或其他所由有用的提出来就更好了
先使劲谢谢

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 < args->count(); i++)
{
KDEApp *widget = new KDEApp;
widget->show();
widget->load(args->url(i));
}
}
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上了~~

...全文
339 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
thisisll 2005-12-14
  • 打赏
  • 举报
回复
恩,谢谢
thisisll 2005-12-13
  • 打赏
  • 举报
回复
http://www.qiliang.net/qt/index.html
这里汉化了
我现从这里看起吧
x86 2005-12-13
  • 打赏
  • 举报
回复
官方网站就有, www.trolltech.com
我记得还有人把文档汉化了,虽然不是最新的,也可以看看.
thisisll 2005-12-13
  • 打赏
  • 举报
回复
恩,我先搜搜QT的文档
x86 2005-12-13
  • 打赏
  • 举报
回复
你可以再试一下用KDevelop编一个QT程序,应该比KDE程序更清晰一些, 更容易搞懂KDE程序的本质.
QT的话,例子非常多, 文档也是很丰富的. 等熟练掌握QT之后回头再来研究KDE程序就可以比较容易抓住KDE相关的内容了.
loserking 2005-12-13
  • 打赏
  • 举报
回复
我觉得学东西还是要学其根本。KDE只是在QT之上封装了很薄的一层。

还是应该从QT文档和QT应用开始,从最基本的地方入手。QT文档里列举了QT的几大基本特性,特别是slot-signal。完全明白这些,才能写出好的KDE/QT应用。
thisisll 2005-12-13
  • 打赏
  • 举报
回复
———————————————————————————————————————————
// see if we are starting with session management
if (app.isRestored())
{
RESTORE(KDEApp);
}
———————————————————————————————————————————
bool KApplication::isRestored ( ) const [inline]
Is the application restored from the session manager?
bool KApplication::isRestored() const { return QApplication::isSessionRestored(); }
bool QApplication::isSessionRestored () const
Returns TRUE if the application has been restored from an earlier session; otherwise returns FALSE.
怎么又冒出来个session?
#define RESTORE(type) { int n = 1;\
while (KMainWindow::canBeRestored(n)){\
(new type)->restore(n);\
n++;}}
又出来一个restore??
CSDN上问了下  loserking(刻舟求剑)和x86(大雪) 回答了我的问题,在这里使劲谢谢
“这个session跟用户会话应该无关。而是应该指的是QSessionManager。QSessionManager提供了一个interface来存储应用的运行状态。比如在windows下存储注册表,linux下存储某个文件中。
KDE应用在QT之上建立了一个自己的目录结构。isRestored()应该是检查具体app所在的目录下的状态配置文件,来判断是否有过以前存储的运行状态。如果以前串行化了运行状态,就根据这个串行化来构造应用,否则构造个新的空应用。
比如,那些toolbar或者停靠窗口,用户改变了它们的位置。当下次启动程序的时候,可能还希望是原来的用户习惯的位置。
...”
"session是指当前回话。退出KDE再进入时可以恢复上一次session,如果你的应用程序支持session,那么你可以在保存和恢复session的时候做相应的事情,比如保存用户操作状态等等"
再看看代码,恩,如果支持session那把上次记录在session manager里的状态读出来并恢复(restore).
———————————————————————————————————————————
// 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 < args->count(); i++)
{
KDEApp *widget = new KDEApp;
widget->show();
widget->load(args->url(i));
}
}
args->clear();
———————————————————————————————————————————
如果不支持session就到这里了
程序运行到了这里了,又搞出一个KCmdLineArgs
KCmdLineArgs * KCmdLineArgs::parsedArgs ( const char * id = 0 )
Access parsed arguments.
This function returns all command line arguments that your code handles. If unknown command-line arguments are encountered the program is aborted and usage information is shown.
Parameters:
id The name of the options you are interested in, can be 0.
这个函数是分析命令行的,把所有命令行的信息放到KCmdLineArgs这个类里
int KCmdLineArgs::count ( ) const
Read the number of arguments that aren't options (but, for example, filenames).
Returns:
The number of arguments that aren't options
这个函数返回的为命令行中不是选项的数量(不包括文件名)
如果命令行输入的都是选项,那直接就实例化我们的app然后show出来
如果有不是的那么就由app来显示一些其他的信息(具体的在后面分析KDEApp的时候再看).

终于把main.cpp看完了
linux_DD 2005-12-13
  • 打赏
  • 举报
回复
mark 下, 再学习
loserking 2005-12-13
  • 打赏
  • 举报
回复
哦,对了。你在用QT开发的时候,建议你多多注意其构造函数。以及你自己派生类的构造函数的初始化列表。往往一个顺序问题,就能产生巨大的差别。
loserking 2005-12-13
  • 打赏
  • 举报
回复
坦率的说,呵呵,没仔细看细节。只是感觉学习方向有点问题。

随着你学习QT的深入,你会慢慢把注意力集中在QT本身上。熟悉基础类库,控制自己应用的slot和signal。由于QT的平台无关性,可能对具体平台的实现,反倒不太关心。

另外一个值得投入精力的是QT的基础代码实现上。不得不称道的是这是个巨大的代码库。由于其class tree非常清晰明确,你可以轻松找到某个具体实现的QT源代码。我来这个坛子也就2周,这里大多数Unix下的功能性问题,都可以在QT代码库里找到答案。

我比较依赖的代码库有QT和ACE,看看代码,查查man,是我Unix程序生活的重要一部分。

KDE部分跟上面2者比,显得微不足道。而且KDE的文档实在太烂了。很是让人郁闷。
bekars 2005-12-13
  • 打赏
  • 举报
回复
我个人看法不要用IDE开发,界面程序除外,但也不要太依靠。
thisisll 2005-12-13
  • 打赏
  • 举报
回复
那谁看到我写的有什么错误没?
源码下载地址: https://pan.quark.cn/s/8d2c461c797c JavaWeb程序设计构成了掌握Web交互式应用程序开发的核心领域,对于初学者来说,精通这一技术具有决定性意义。在“JavaWeb程序设计(第三版)作业答案”中,我们可以预期获得针对该教材习题的一系列深入解析,从而协助学习者强化知识体系。 JavaWeb所包含的技术组件涵盖了Servlet、JSP(JavaServer Pages)、JDBC(Java Database Connectivity)以及各类框架如Spring MVC、Struts等。Servlet是Java平台提供的一种扩展服务器功能的接口,能够处理HTTP请求并生成相应的反馈。JSP则是一种用于构建动态网页的工具,它支持开发者将HTML代码与Java代码进行整合编,从而简化了Web应用程序的开发流程。 作业答案通常会涉及以下几个核心内容: 1. **Servlet基础**:可能包含Servlet生命周期、init(), service(), destroy()方法的应用,以及如何在web.xml文件中设定Servlet的映射关系。 2. **JSP基础**:JSP的九大内置对象,如request、response、session、application等的使用,以及EL(Expression Language)和JSTL(JavaServer Pages Standard Tag Library)的实际操作。 3. **HTTP协议理解**:GET和POST请求方法的差异,请求头与响应头的应用,以及会话管理的概念阐释。 4. **JDBC数据库操作**:与数据库建立连接,执行SQL指令,处理查询结果集,以及...
源码链接: https://pan.quark.cn/s/a4b39357ea24 斐讯K2是一款广受用户青睐的无线路由器,其运行表现稳定且具备较高的可操作性,在DIY爱好者群体中拥有极高的声誉。本资料将系统性地阐述斐讯K2的固件刷机方法及其关联的技术要。固件升级是路由器爱好者改善设备性能、扩展功能的一种普遍手段,经由替换出厂固件,能够达成更加个性化的网络配置、增强安全防护等目标。斐讯K2固件资源库涵盖了多种知名的非官方固件,诸如Tomato Pheonix 不死鸟、高恪、PandoraBox 潘多拉等,这些固件均具备独特的优势,能够适配不同用户的需求。 1. Tomato Pheonix 不死鸟:Tomato是一款立足于Linux的开源固件,以其精巧、高效而备受推崇。不死鸟版本是专门为华硕及斐讯路由器优化的分支,提供了卓越的QoS(服务质量)配置、详尽的图表监控以及便捷的固件升级途径。对于那些需要精准调控带宽和监测网络状态的用户而言,这是一个理想的选项。 2. 高恪:高恪固件是OpenWrt的定制化版本,着重于操作的便捷性和运行的可靠性,特别适合对路由器操作不甚熟悉的用户群体。它提供了一些实用的功能,例如内置的广告屏蔽、快速测速工具等,同时保留了OpenWrt的适应性。 3. PandoraBox 潘多拉:潘多拉盒是另一款基于OpenWrt的固件,它以丰富的插件库和强大的自定义潜力而闻名。用户能够依据个人需求安装各类插件,实现更多功能,如远程接入、DDNS(动态域名解析服务)等。 4. 官方固件的纯净版本与定制版本:官方固件通常更侧重于稳定性,纯净版意味着未预置额外的应用或服务,适合注重稳定性的用户。定制版则可能包含了制造商的特色功能或优...

23,223

社区成员

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

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