Confused about Hello World include files

Wes Gray smiths at alumni.cse.ucsc.edu
Tue Nov 19 04:31:52 GMT 2002


I am still working to get a Hello World app to compile with
KDevelop.  I think I am all set except when it links I get
a multiple definition error.  My program has 5 files:
	main.cpp
	newtry.cpp
	newtry.h
	ntwin.cpp
	ntwin.h

The newtry* files are the base class of the program, and the
ntwin* files are created from ntwin.ui which I made with QTDesigner.

I have tried several combinations of including things, and also
I tried some forward declarations, but nothing has worked so far,
either I get something undefined, or multiple defines.  I am a little
sketchy on C++ syntax, so maybe this is a newbie mistake.  What
needs to include what?  Anyone willing to take a look at the code
and tell me where I am lost?  Thanks!  -Wes

----main.cpp----
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>

#include "newtry.h"

static const char *description =
	I18N_NOOP("Newtry");
// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
	
	
static KCmdLineOptions options[] =
{
  { 0, 0, 0 }
  // INSERT YOUR COMMANDLINE OPTIONS HERE
};

int main(int argc, char *argv[])
{

  KAboutData aboutData( "newtry", I18N_NOOP("Newtry"),
    VERSION, description, KAboutData::License_GPL,
    "(c) 2002, Wes Gray", 0, 0, "");
  aboutData.addAuthor("Wes Gray",0, "");
  KCmdLineArgs::init( argc, argv, &aboutData );
  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.

  KApplication a;
  Newtry *newtry = new Newtry();
  a.setMainWidget(newtry);
  newtry->resize(400,300); // New line 1
  newtry->addWidgets(&a);  // New line 2
  newtry->show();  

  return a.exec();
}

----newtry.h-----
#ifndef NEWTRY_H
#define NEWTRY_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kapp.h>
#include <qwidget.h>

/** Newtry is the base class of the project */
class Newtry : public QWidget
{
  Q_OBJECT 
  public:
    /** construtor */
    Newtry(QWidget* parent=0, const char *name=0);
    /** destructor */
    ~Newtry();
  /** No descriptions */
  void addWidgets(KApplication *a);
};

#endif

----newtry.cpp----
#include "ntwin.h"
#include "newtry.h"

Newtry::Newtry(QWidget *parent, const char *name) : QWidget(parent, name)
{
}

Newtry::~Newtry()
{
}
/** No descriptions */
void Newtry::addWidgets(KApplication *a){
   ntwin *new_widgets = new ntwin (this, "Widgets");

   new_widgets->setupQuit (a); 
}

----ntwin.h----
#ifndef NTWIN_H
#define NTWIN_H

#include <qvariant.h>
#include <qdialog.h>
#include <kapp.h>

class QVBoxLayout; 
class QHBoxLayout; 
class QGridLayout; 
class QLabel;
class QPushButton;

class ntwin : public QDialog
{ 
    Q_OBJECT

public:
    ntwin( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, 
WFlags fl = 0 );
    ~ntwin();
  /** No descriptions */
  void setupQuit(KApplication *a);

    QLabel* TextLabel1;
    QPushButton* PushButton1;


};

----ntwin.cpp----
#include "ntwin.h"

#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>

/* 
 *  Constructs a ntwin which is a child of 'parent', with the 
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
ntwin::ntwin( QWidget* parent,  const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
    if ( !name )
	setName( "ntwin" );
    resize( 249, 218 ); 
    setCaption( tr2i18n( "Form1" ) );

    TextLabel1 = new QLabel( this, "TextLabel1" );
    TextLabel1->setGeometry( QRect( 70, 50, 65, 20 ) ); 
    TextLabel1->setText( tr2i18n( "NewTryWin" ) );

    PushButton1 = new QPushButton( this, "PushButton1" );
    PushButton1->setGeometry( QRect( 70, 140, 84, 22 ) ); 
    PushButton1->setText( tr2i18n( "PushButton1" ) );
}

/*  
 *  Destroys the object and frees any allocated resources
 */
ntwin::~ntwin()
{
    // no need to delete child widgets, Qt does it all for us
}

#include "ntwin.moc"



-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list