[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    RE: Hello World newbie woes -- SOLVED
From:       "Martin Welch" <martin () welch ! eclipse ! co ! uk>
Date:       2004-04-03 19:40:19
Message-ID: GIEKKMAAMELBNKEJJKHGAEEMCMAA.martin () welch ! eclipse ! co ! uk
[Download RAW message or body]

Done it. For the benefit of others I've included all the source files, my
modified build script and a simple makefile.

Removing -fno-rtti and building with the correct libraries did the trick!

I know this isn't exactly earth shattering stuff but is it not worth
updating the hello world tutorial to build to KDE3 rather than KDE1?

Thanks for all your help,

Martin

-----------makefile------------
INC =-I/usr/include -I/usr/lib/qt3/include
LIB =-L/usr/lib -L/usr/lib/qt3/lib -lkdeui -lkdecore -lqt-mt -ldl
MOC =/usr/lib/qt3/bin/moc

OBJS= \
       main.o \
       khello.o

khello: $(OBJS)
	c++ $(LIB) -o khello $(OBJS)

khello.moc: khello.h
	$(MOC) -o khello.moc khello.h

main.o: main.cpp khello.h
	c++ -c $(INC) main.cpp -o main.o

khello.o: khello.cpp khello.moc
	c++ -c $(INC) khello.cpp -o khello.o
-----------build---------------
c++ -c -I/usr/include -I/usr/lib/qt3/include -g main.cpp -o main.o
/usr/lib/qt3/bin/moc -o khello.moc khello.h
c++ -c -I/usr/include -I/usr/lib/qt3/include -g khello.cpp -o khello.o
c++ -L/usr/lib -L/usr/lib/qt3/lib -lkdeui -lkdecore -lqt-mt -ldl -o
khello -g main.o khello.o
-----------main.cpp------------
#include "khello.h"

int main( int argc, char **argv )
{
  KApplication a( argc, argv, "khello" );
  KHello *w = new KHello();
  w->setGeometry(100,100,200,100);

  a.setMainWidget( w );
  w->show();
  return a.exec();
}
----------khello.h-------------
#include <kapp.h>
#include <kmainwindow.h>
#include <kmessagebox.h>
#include <qpushbutton.h>
#include <kmenubar.h>
#include <kpopupmenu.h>

class KHello : public KMainWindow
{
  Q_OBJECT
public:
  KHello();
  void closeEvent(QCloseEvent *);
public slots:
  void slotHello();
  void slotExit();
private:
  QPushButton *btnHello;
  QPushButton *btnExit;
  KMenuBar *menu;
  KPopupMenu *file, *help;
};
----------khello.cpp-----------
#include "khello.moc"
#include <kmessagebox.h>

KHello::KHello() : KMainWindow()
{
  btnHello = new QPushButton("Hello", this);
  btnHello->setGeometry(45,30,50,25);
  btnHello->show();
  connect(btnHello, SIGNAL(clicked()), this, SLOT(slotHello()));

  btnExit = new QPushButton("Exit", this);
  btnExit->setGeometry(105,30,50,25);
  btnExit->show();
  connect(btnExit, SIGNAL(clicked()), this, SLOT(slotExit()));

  file = new KPopupMenu();
  file->insertItem("&Hello", this, SLOT(slotHello()));
  file->insertItem("&Exit", this, SLOT(slotExit()));

  help = helpMenu("KHello\nby Daniel Marjamäki\nUpdated by David Leimbach");

  menu = menuBar();
  menu->insertItem("&File", file);
  menu->insertItem("&Help", help);
}

void KHello::closeEvent(QCloseEvent *e)
{
  kapp->beep();
  KMainWindow::closeEvent(e);
}

void KHello::slotHello()
{
  KMessageBox::information(this, "Hello World!", "Important");
}

void KHello::slotExit()
{
  close();
}
-------------------------------
-----Original Message-----
From: Martin Welch [mailto:martin@welch.eclipse.co.uk]
Sent: 31 March 2004 11:58
To: Kde-Devel
Subject: Hello World newbie woes


I'm having difficulty getting KHello to build and run on my new Mandrake 10
box.

Following the tutorial on kdevelop.kde.org I finally managed to get this to
build and run:

--------------khello.cpp------------
#include <kapp.h>
#include <kmainwindow.h>

int main( int argc, char **argv )
{
  KApplication a( argc, argv, "khello" );
  KMainWindow *w = new KMainWindow();
  w->setGeometry(100,100,200,100);

  a.setMainWidget( w );
  w->show();
  return a.exec();
}
--------------build1-----------------
c++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti khello.cpp -o
../khello.o
c++ -L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore $QTDIRqt -ldl -o ../khello
../khello.o
------------------------------------

The next attempt builds but crashes when I try to run it.

--------------main.cpp-------------------
#include "khello.h"

int main( int argc, char **argv )
{
  KApplication a( argc, argv, "khello" );
  KHello *w = new KHello();
  w->setGeometry(100,100,200,100);

  a.setMainWidget( w );
  w->show();
  return a.exec();
}
-------------khello.h-----------------------
#include <kapp.h>
#include <kmainwindow.h>
#include <kmessagebox.h>
#include <qpushbutton.h>
#include <kmenubar.h>
#include <kpopupmenu.h>

class KHello : public KMainWindow
{
  Q_OBJECT
public:
  KHello();
  void closeEvent(QCloseEvent *);
public slots:
  void slotHello();
  void slotExit();
private:
  QPushButton *btnHello;
  QPushButton *btnExit;
  KMenuBar *menu;
  KPopupMenu *file, *help;
};
------------khello.cpp---------------------
#include "khello.moc"
#include <kmessagebox.h>

KHello::KHello() : KMainWindow()
{
  btnHello = new QPushButton("Hello", this);
  btnHello->setGeometry(45,30,50,25);
  btnHello->show();
  connect(btnHello, SIGNAL(clicked()), this, SLOT(slotHello()));

  btnExit = new QPushButton("Exit", this);
  btnExit->setGeometry(105,30,50,25);
  btnExit->show();
  connect(btnExit, SIGNAL(clicked()), this, SLOT(slotExit()));

  file = new KPopupMenu();
  file->insertItem("&Hello", this, SLOT(slotHello()));
  file->insertItem("&Exit", this, SLOT(slotExit()));

  help = helpMenu("KHello\nby Daniel Marjamäki\nUpdated by David Leimbach");

  menu = menuBar();
  menu->insertItem("&File", file);
  menu->insertItem("&Help", help);
}

void KHello::closeEvent(QCloseEvent *e)
{
  kapp->beep();
  KMainWindow::closeEvent(e);
}

void KHello::slotHello()
{
  KMessageBox::information(this, "Hello World!", "Important");
}

void KHello::slotExit()
{
  close();
}
---------------build2---------------------
c++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti main.cpp -o main.o
$QTDIR/bin/moc khello.h -o khello.moc
c++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti khello.cpp -o khello.o
c++ -L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore $QTDIRqt -ldl -o khello
main.o khello.o
------------------------------------

I'm fairly confident that the source code is right and its my build scripts
that are wrong.
Q1: Why does the output files (hello.o etc) always have an \r appended to
the names?

The only thing in my scripts that's different is that I've changed -qt to
$QTDIRqt since
ld couldn't find qt. My understanding here is -L/blah says the compiler
should look in /blah for libraries and -lfoo says the library is called foo.
At runtime my program 'knows' to load foo but doesn't know where foo
resides. If, OTOH, I use -l/blah/foo my program will expect to load foo from
/blah -- the path is hardcoded.
Q2: On my machine then (L/blah -lfoo) == (-l/blah/foo) ?
Q3: Am I talking rubbish? :)

Could anyone advise?

Thanks,

Martin

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic