PDA

View Full Version : I am working on a POS project



foxrider
13th April 2014, 09:57
I am totally new to qt. For the administration menu i have few options.What i want is when ever i trigger any menu field option one new window popup should come.To which i can use lineEdit ,labels and push button.That popup should also be connected with the database.I do not want to use designer form class because i have many field to go with.So it is not a good idea to add several designer form class.

void MainWindow::on_actionChange_password_triggered()
{
}
It would be helpful with anyone will write the code for the trigger event which will popup a dialog window.In the dialog window i want to use lineEdit ,label and push button .So that i could change the password .That popupwindow should also be connected with database.

NOTE :- I do not want to use designer form class,for the purpose as i have so many popup to go with.


Thanks in advance

anda_skoa
13th April 2014, 10:48
Whether you use designer or code to create a dialog doesn't affect showing the dialogs:

you create an instance of the class and then call show() for a modeless dialog or exec() for a modal dialog.

My recommendation would be to use designer, especially since you are new to Qt.
Even for experiences Qt developers it is usually a waste of time to write many lines of C++ code that can be autotically derived from an interactively modifyable visualisation.

Cheers,
_

foxrider
13th April 2014, 16:13
Thanks for the reply.
The think is that i want to use the code like this
void MainWindow::on_actionChange_password_triggered()
{
QObject::connect(ui->actionChange_password,SIGNAL(triggered()),dialog,S LOT(show()));
}
to create popupwindow on each triggered field.I do not want to add designer form class for each field.Pls help me with the code it self.
Thanks once again.

anda_skoa
13th April 2014, 17:49
I am afraid I don't understand.

Not wanting to use designer for the thing it is good at aside, are the following assumptions correct?

You have some QAction instances in your main window?
And you want different dialogs to show for each of them?
And each action should only show a single instance of "its" dialog?

Cheers,
_

foxrider
13th April 2014, 20:16
Yes your assumption is right.
I am helping u with my all codes.
-------------
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtDebug>
#include <QFileInfo>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_actionChange_password_triggered();
public:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H


-------------
main.cpp
--------------
include "mainwindow.h"
#include <QApplication>

#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}


--------------------

mainwindow.cpp

--------------------
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDialog>
#include<qdialog.h>
#include <QLibrary>
#include <QtGui>
#include <QTextEdit>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_actionChange_password_triggered() // change password field,refer to figure attach.In Fig have adminstration have
// submenu for those sub menu popup should come
{

QObject::connect(ui->actionChange_password,SIGNAL(triggered()),QDialog, SLOT(show()));

}


in the line : QObject::connect(ui->actionChange_password,SIGNAL(triggered()),QDialog, SLOT(show()));

i want to have the code which will create popup window for change password in this case.As i do not want to add one extra designer form class because there are so many field like add user,remove user,update user.I want to have separate popup for for each menu content (it should be like if i click on change password a new popup should be there) .So that i can use lineEdit and other options with window popup.If possible help me with code.I am tired trying
Thanks

anda_skoa
13th April 2014, 20:31
I am not sure what your intention with the connect is, other than it obviously being wrong in syntax.

The action is already connected to that very slot.

Just create an instance of your password change dialog and show it (this will open multiple dialogs if the action is triggered multiple times)


void MainWindow::on_actionChange_password_triggered()
{
// assumes PasswordChangeDialog deletes itself when being closed
PasswordChangeDialog *dialog = new PasswordChangeDialog(this);
dialog->show();
}


Keep the instance if you only want one.


void MainWindow::on_actionChange_password_triggered()
{
if (m_passwordChangeDialog == 0) {
m_passwordChangeDialog = new PasswordChangeDialog(this);
}
m_passwordChangeDialog->show();
m_passwordChangeDialog->raise();
m_passwordChangeDialog->activateWindow();
}


Use exec() if it should be modal.


void MainWindow::on_actionChange_password_triggered()
{
PasswordChangeDialog dialog(this);
dialog.exec();
}


Whether you use designer for password change dialog or code it manually is really irrelevant to its usage. Manually coding it is way more work of course.

Cheers,
_

foxrider
15th April 2014, 13:48
Thanks for the consideration once again.
I am sorry for late reply.
As i tried compiling with your posted code.I am getting the errors.Please refer to the screen shot.10287.
I am unable to guess that what is causing the errors.
Help me
Thanks !!!

Note;- I have not changed any files code it is same as i had posted above.

anda_skoa
15th April 2014, 14:56
Well, the compiler rightfully complains about you using a type (class) that it does not know about (PasswordChangeDialog).

Add such a class to your project and include its header in mainwindow.cpp

C++ might sometimes feel like magic, but it is not :)

Cheers,
_

foxrider
15th April 2014, 16:03
Please help me with the code.I do not know where to declare the class and how to use it.
Thanks

anda_skoa
15th April 2014, 19:36
Creating a new class is really one of the most basic things in C++.
You'll have to look at least a bit into C++ before you can start creating applications in C++.

There are a lot of C++ beginner tutorials available on the web,

Cheers,
_

foxrider
16th April 2014, 20:02
Creating a new class is really one of the most basic things in C++.
You'll have to look at least a bit into C++ before you can start creating applications in C++.

There are a lot of C++ beginner tutorials available on the web,

Cheers,
_

Well now i have some elementary knowledge of creating object and classes.Now i have created a class PasswordChangeDialog in mainwindow.h file and i have included this header file to mainwindow.cpp. Here is my mainwindow.h file
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtDebug>
#include <QFileInfo>
namespace Ui {
class MainWindow;
}

class PasswordChangeDialog
{

};

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_actionChange_password_triggered();
public:
Ui::MainWindow *ui;
//MyDialog *mDialog;

};

#endif // MAINWINDOW_H


Case 1. Now when i am running the code i am getting the error as shown in the screen shot10289

Case 2. When i am trying to pass the reference of object (change) to pointer i am getting error as shown in the shot10290


NOTE :- It is your wish to consider case 2.I tried it while i was learning pointer and object.You can continue with case 1.

I am afraid now what to do.Help !!!
Thanks

sulliwk06
16th April 2014, 20:54
Well your class PasswordChangeDialog has no constructor. It also has no function called show. What is it you think this class you are creating is supposed to do?

It sounds like you want this class to inherit from QDialog. But judging from the difficulties you are having I would recommend finding a tutorial on creating popup dialogs.

foxrider
21st April 2014, 14:48
Thanks a lot Mr anda_skoa and sulliwk06. Actually i was trying to inherit QDialog class without declearing it.I am able to do it now.