From ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdecore/tests/testqtargs.cpp | 104 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 kdecore/tests/testqtargs.cpp (limited to 'kdecore/tests/testqtargs.cpp') diff --git a/kdecore/tests/testqtargs.cpp b/kdecore/tests/testqtargs.cpp new file mode 100644 index 000000000..918b07735 --- /dev/null +++ b/kdecore/tests/testqtargs.cpp @@ -0,0 +1,104 @@ +/* + testqtargs -- is there really a bug in KCmdLineArgs or am I on crack? + + I used the following compile options: + + g++ -g -Wall -o testqtargs testqtargs.cpp -I/usr/X11R6/include \ + -I/opt/qt3/include -I/opt/kde3/include -L/usr/X11R6/lib -L/opt/qt3/lib \ + -L/opt/kde3/lib -lqt -lkdecore + + if invoked like this ./testqtargs --bg blue --caption something --hello hi + + The program should list argv[] then produce output like this: + + qt arg[0] = background + qt arg[1] = blue + arg bg = blue + arg caption = something + arg hello = hi + + Instead for me it prints: + + qt arg[0] = -background + qt arg[1] = blue + arg caption = something + arg hello = hi + + See the extra dash in qt arg[0]? I believe that is the cause of the problem. + --bg is aliased to --background but If you try it with --background or + -background, you get the same thing. + + in kdecore/kapplication.cpp, KCmdLineOption qt_options is defined and used + by the static method Kapplication::addCmdLineOptions to add the Qt options + but its' entries look like this: + + { "background ", I18N_NOOP("sets the default background color and an\n +application palette (light and dark shades are\ncalculated)."), 0}, + + it looks for "background" instead of "-background" so never find the arg. + + Software: g++ 2.95, kdelibs from CVS Jan 28, Qt 3.01 + OS: Debian GNU/Linux 3.0 (sid) + + +*/ + +#include +#include +#include +#include + +static const KCmdLineOptions options[] = +{ + { "hello ", I18N_NOOP("Says hello"), 0 }, + KCmdLineLastOption +}; + +int main(int argc, char *argv[]) +{ + for (int i = 0; i < argc; i++) + { + qDebug("argv[%d] = %s", i, argv[i]); + } + KAboutData aboutData( "testqtargs", I18N_NOOP("testqtargs"), + "1.0", I18N_NOOP("testqtargs"), KAboutData::License_GPL, + "", "", "", ""); + + KCmdLineArgs::init(argc, argv, &aboutData); + KCmdLineArgs::addCmdLineOptions(options); + + KCmdLineArgs *qtargs = KCmdLineArgs::parsedArgs("qt"); + for (int i = 0; i < qtargs->count(); i++) + { + qDebug("qt arg[%d] = %s", i, qtargs->arg(i)); + } + + KApplication app; + + KCmdLineArgs *kdeargs = KCmdLineArgs::parsedArgs("kde"); + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + // An arg set by Qt + if(qtargs->isSet("background")) + { + qDebug("arg bg = %s", (const char*)qtargs->getOption("background")); + } + // An arg set by KDE + if(kdeargs->isSet("caption")) + { + qDebug("arg caption = %s", (const char*)kdeargs->getOption("caption")); + } + // An arg set by us. + if(args->isSet("hello")) + { + qDebug("arg hello = %s", (const char*)args->getOption("hello")); + } + args->clear(); + + QWidget *w = new QWidget(); + app.setMainWidget(w); + w->show(); + + return app.exec(); +} + -- cgit v1.2.1