Wednesday, August 03, 2005

[Qt] Re: adding custom widgets

Hello,

thanks for anwsering my message.
I've solved the problem by adding to the project
the *.cpp, *.h and the moc file of my custom widget.
Should be done that when adding a custom widget to a project?

I don't really know if I'm solving the problem in the correct way.
However, i paste here everything i think you ask me for.

1.the code of my project:

unix {
UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj
}

TEMPLATE = app
LANGUAGE = C++

CONFIG += qt warn_on release


HEADERS += C:/Qt/3.3.1/tools/designer/examples/vcr/vcr.h
SOURCES += main.cpp C:/Qt/3.3.1/tools/designer/examples/vcr/moc_vcr.cpp C:/Qt/3.3.1/tools/designer/examples/vcr/vcr.cpp
FORMS = mainwindowvcr.ui
IMAGES = images/filenew images/fileopen images/filesave images/print images/undo images/redo images/editcut images/editcopy images/editpaste images/searchfind


2. the vcr.cpp(here is defined the constructor of the widget)

#include "vcr.h"
#include
#include

static const char * rewind_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
"................",
".++..........++.",
".++........++++.",
".++......++++++.",
".++....++++++++.",
".++..++++++++++.",
".++++++++++++++.",
".++++++++++++++.",
".++++++++++++++.",
".++++++++++++++.",
".++..++++++++++.",
".++....++++++++.",
".++......++++++.",
".++........++++.",
".++.........+++.",
"................"};

static const char * play_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
"................",
".++.............",
".++++...........",
".++++++.........",
".++++++++.......",
".++++++++++.....",
".++++++++++++...",
".+++++++++++++..",
".+++++++++++++..",
".++++++++++++...",
".++++++++++.....",
".++++++++.......",
".++++++.........",
".++++...........",
".+++............",
"................"};

static const char * next_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
"................",
".++.....+.......",
".+++....++......",
".++++...+++.....",
".+++++..++++....",
".++++++.+++++...",
".+++++++++++++..",
".++++++++++++++.",
".++++++++++++++.",
".+++++++++++++..",
".++++++.+++++...",
".+++++..++++....",
".++++...+++.....",
".+++....++......",
".++.....+.......",
"................"};

static const char * stop_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
"................",
".++++++++++++++.",
".++++++++++++++.",
".++++++++++++++.",
".+++........+++.",
".+++........+++.",
".+++........+++.",
".+++........+++.",
".+++........+++.",
".+++........+++.",
".+++........+++.",
".+++........+++.",
".++++++++++++++.",
".++++++++++++++.",
".++++++++++++++.",
"................"};


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

QPushButton *rewind = new QPushButton( QPixmap( rewind_xpm ), 0, this,
"vcr_rewind" );
layout->addWidget( rewind );
connect( rewind, SIGNAL(clicked()), SIGNAL(rewind()) );

QPushButton *play = new QPushButton( QPixmap( play_xpm ), 0, this,
"vcr_play" );
layout->addWidget( play );
connect( play, SIGNAL(clicked()), SIGNAL(play()) );

QPushButton *next = new QPushButton( QPixmap( next_xpm ), 0, this,
"vcr_next" );
layout->addWidget( next );
connect( next, SIGNAL(clicked()), SIGNAL(next()) );

QPushButton *stop = new QPushButton( QPixmap( stop_xpm ), 0, this,
"vcr_stop" );
layout->addWidget( stop );
connect( stop, SIGNAL(clicked()), SIGNAL(stop()) );
}

3. the vcr.h

#ifndef VCR_H
#define VCR_H
#include

class Vcr : public QWidget
{
Q_OBJECT
public:
Vcr( QWidget *parent = 0, const char *name = 0 );
~Vcr() {}
signals:
void rewind();
void play();
void next();
void stop();
};
#endif

Thousand thanks

ferris

>From: "Wu Yinghui, Freddie"
>Reply-To: yhwu@volumeinteractions.com
>To: qt-interest@trolltech.com
>CC: qt-interest@trolltech.com
>Subject: Re: adding custom widgets
>Date: Wed, 03 Aug 2005 15:33:40 +0800
>
>ferris ferris wrote:
>>Hi,
>>
>>i use qt 3.3.1 with windows xp. I'm learning how to use custom widgets
>>with the qt assistant(Qt Designer Manual-Creating Custom Widgets) and I
>>get an error when i try linking the project.
>>
>>I added the vcr custom widget shown in the assistant to the toolbox and
>>after that, that widget to a main window. I create a main and when i
>>compile i get this error:
>>
>>mainwindowvcr.obj: error LNK2001 unresolved external symbol "public:
>>__thiscall Vcr::Vcr(class QWidget *, char const *)" ...
>>
>>I tried adding the vcr.h and vcr.cpp to the project. Then, both the
>>compilation and linkation run ok. However, the executable i get is not
>>what i expected. What i get is the custom widget i added without the rest
>>of the widgets i added to my main window(radio buttons, push buttons ...)
>>
>>I need to learn how add a custom widget and i can't find help for this
>>particular problem.
>>
>>
>>I hope this information will be enoght, if won't please tell me.
>>Thanks in advance.
>>
>
>I'd be more helpful, I guess, if you can provide your project and source
>files. The error message you showed above is just a simple linking error,
>from which I cannot really tell what you did wrongly. (But first, have you
>checked that you have that constructor declared but not defined?)
>
>Cheers,
>
>Freddie
>
>--
>Wu Yinghui, Freddie
>Research & Development
>Software Engineer
>
>Volume Interactions Pte Ltd
>1 Kim Seng Promenade, #12-01
>Great World City East Tower
>Singapore 237994
>Tel: +65 62226962 (Ext 216)
>Fax: +65 62226215
>Email: yhwu@volumeinteractions.com
>URL: http://www.volumeinteractions.com
>
>Important: This message is intended for the recipient(s) addressed above.
>It contains privileged and confidential information. If you are not the
>intended recipient, please notify the sender immediately by replying to
>this message and then delete it from your system. You must not read, copy,
>use, or disseminate this communication in any form. Thank you.
><< yhwu.vcf >>
><< signature.asc >>

0 Comments:

Post a Comment

<< Home