View Full Version : Compilation failed ... I don't know why :(

26th January 2006, 16:47

I am pretty newbie in developpement so my mistake should be easy to find out, but not for me.

I have picked up some line of code in order do develop a simple custom widget but the compilation failed.

For the .h
#include <qwidget.h>

class QLineEdit;
class QPushButton;

class FileChooser : public QWidget
Q_ENUMS( Mode )
Q_PROPERTY( Mode mode READ mode WRITE setMode )
Q_PROPERTY( QString fileName READ fileName WRITE setFileName )

FileChooser( QWidget *parent = 0, const char *name = 0);
enum Mode { File, Directory };
QString fileName() const;
Mode mode() const;

public slots:
void setFileName( const QString &fn );
void setMode( Mode );

void fileNameChanged( const QString & );

private slots:
void chooseFile();

QLineEdit *lineEdit;
QPushButton *button;
Mode md;

For the .cpp
#include "filechooser.h"
#include "qlayout.h"
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qfiledialog.h>

FileChooser::FileChooser( QWidget *parent, const char *name )
: QWidget( parent, name ), md( File )
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );

lineEdit = new QLineEdit( this, "filechooser_lineedit" );
layout->addWidget( lineEdit );
connect( lineEdit, SIGNAL( textChanged( const QString & ) ), this,
SIGNAL( fileNameChanged( const QString & ) ) );

button = new QPushButton( "...", this, "filechooser_button" );
button->setFixedWidth( button->fontMetrics().width( " ... " ) );
layout->addWidget( button );

connect( button, SIGNAL( clicked() ), this, SLOT( chooseFile() ) );
setFocusProxy( lineEdit );

void FileChooser::setFileName( const QString &fn )
lineEdit->setText( fn );

QString FileChooser::fileName() const
return lineEdit->text();

Mode FileChooser::mode() const
return md;

void FileChooser::setMode( Mode m )
md = m;

void FileChooser::chooseFile()
QString fn;

if( mode() == File )
fn = QFileDialog::getOpenFileName( lineEdit->text(), QString::null, this );
fn = QFileDialog::getExistingDirectory( lineEdit->text(), this);

if ( !fn.isEmpty() )
lineEdit->setText( fn );
emit fileNameChanged( fn );

So here is the code ... could someone help me plese ?

26th January 2006, 17:39
#include "qlayout.h" with
#include <qlayout.h>
You should also post the error(s) that the compiler presented.
Finally please, please use the [C O D E] tags around your sources ;)

27th January 2006, 10:40
Thanks, it is ok now.

Next time I'll use the code tags.

Is there a way to put a [SOLVE] tag in the title message once the problem is solved ? (I've seen that on other forums, it's quite cool to only focus on specific messages, those that are not solved yet).

27th January 2006, 10:48
Is there a way to put a [SOLVE] tag in the title message once the problem is solved ?
You could try to edit your first post, but I'm not sure if it will work (vBulletin distinguishes between thread title and first post title).