July 9, 2011

r@h@ r@h@
Lab Rat
24 posts

[solved]how can i include a class in a dialog?


hello again.
in my program what shoudl i do if i want to include an object class(User class in here) that i myself define it ,
and then use that class in one of functions (on_cmdOk_clicked() )of my dialog(Signup in here)?
i try these code:

  1. #include "signup.h"
  2. #include "ui_signup.h"
  3. #include "../User.h"
  6. void Signup::on_cmdOk_clicked()
  7. {
  8.     QString UserName=ui->UserName->text();
  9.     QString PassWord=ui->PassWord->text();
  10.     QString FirstName=ui->FirstName->text();
  11.     QString LastName=ui->LastName->text();
  13.     Users users;
  14.     users.insert(UserName,PassWord,FirstName,LastName,int id=-1);
  16. }

but i recieve below error:

..\signup.cpp:3:21: error: ../User.h: No such file or directory
..\signup.cpp: In member function ‘void Signup::on_cmdOk_clicked()’:
..\signup.cpp:36: error: ‘Users’ was not declared in this scope
..\signup.cpp:36: error: expected ‘;’ before ‘users’
..\signup.cpp:37: error: ‘users’ was not declared in this scope
..\signup.cpp:37: error: expected primary-expression before ‘int’

and this is my .pro file:

  1. TARGET = NoteBook
  2. TEMPLATE = app
  3. SOURCES += dialog.cpp \
  4.     ../source/src/main.cpp \
  5.     ../signup.cpp
  6. HEADERS += dialog.h \
  7.     ../source/src/User.h \
  8.     ../source/src/TagRelation.h \
  9.     ../source/src/Tag.h \
  10.     ../source/src/header.h \
  11.     ../source/src/Content.h \
  12.     ../source/src/BaseRelation.h \
  13.     ../source/src/BaseIndex.h \
  14.     ../source/src/BaseEntity.h \
  15.     ../signup.h
  16. FORMS += dialog.ui \
  17.     ../signup.ui
  18. INCLUDEPATH += ../

if someone knows the answer please help me.
thank you.

3 replies

July 9, 2011

koahnig koahnig
Robot Herder
2987 posts

It looks like your include path is wrong. The compiler complains that the include file “../Users.h” is not found.

r@h@ wrote:
  1. #include "signup.h"
  2. #include "ui_signup.h"
  3. #include "source/src/User.h"

This include section would look a bit more logical based on the information of your .pro file.

July 9, 2011

r@h@ r@h@
Lab Rat
24 posts

yeah .you’re right.
it works now properly.
thank you to reply and help me.
in my User class there is a file that save information of users.
if i want to insert a new user in (on_cmdOk_clicked()) function,can i get an object from User class in main.cpp and use that object and it’s functions (like insert) in the above function of Signup.cpp(Signup is a dialog in my program)?
because if i want to get an object of User class in that function (on_cmdOk_clicked()) ,whenever that ok button be pushed ,an object of User class and then a file iwill be create and it’s not true.
can you help me in this topic too?

July 11, 2011

koahnig koahnig
Robot Herder
2987 posts

I just want to make you aware of on option to store such information user names and related information into a file. QSettings [doc.qt.nokia.com] Typically QSettins facilitates that quite nicely for different applications and platforms. On windows you have the option to store in ini-files and also for linux the data are more easily maintained compared to hand-knitted files. You may use the file structure behind the scenes and open it from any place in your program. Maybe that would be of help.

I cannot answer your quite detailed question above. main.cpp is just a name of a file which presumably holds most or all information of your code. It all depends on what you are trying to achieve and how your program is setup. I guess it is somehow possible, but there is no way to provide details without knowing more. Anyhow, I think it would be good if you have a look to the possibilities of QSettings.

  ‹‹ [solved]calling a dialog in another dialog      [SOLVED] QListView - To select a disabled item ››

You must log in to post a reply. Not a member yet? Register here!