PDA

View Full Version : problem in window to enter information



robelle
2nd October 2012, 08:43
Hi,
i want when clic in button i see window where i enter name and number

i make like that


Add = new QToolButton(page_13);
Add->setObjectName(QString::fromUtf8("Add"));
Add->setGeometry(QRect(150, 9, 51, 31));
Add->setText("Aadd");
connect(Add, SIGNAL(clicked()),mQOgreWidget,SLOT(AddInfo()));

in AddInfo() i make like that


QString Nom_Segment = QInputDialog::getText(this, "Name", "Name");
int entier = QInputDialog::getInteger(this, "Number", "Number");

But like that i see one window where i enter just the name when i close it i see another one where i enter the number

BUT it's not what i want i want to enter the a both in one window

wysota
2nd October 2012, 08:55
Implement a dialog that will contain both fields.

robelle
2nd October 2012, 09:00
Implement a dialog that will contain both fields.
how i do that ?

did you mean that i define new widget with 2 QLineEdit,layout ?

wysota
2nd October 2012, 09:04
how i do that ?
A good place to start would be to do any tutorial on Qt that is based on QDialog.

robelle
2nd October 2012, 10:06
ok
as i see here
http://doc.qt.digia.com/4.6/dialogs-extension.html
the qdialog in my case will be a widget

Added after 57 minutes:

I have just another question
i make like that

connect(Add, SIGNAL(clicked()),mQOgreWidget,SLOT(showdialogue() ));
and


void MainWindow::showdialogue()
{
QWidget fenetre;

QLineEdit *nom = new QLineEdit;
QLineEdit *nombre = new nombre;

QFormLayout *layout = new QFormLayout;
layout->addRow("nom", nom);
layout->addRow("nombre", nombre);

fenetre.setLayout(layout);

fenetre.show();

my question is : the widget fenêtre i must define it in another class ?

wysota
2nd October 2012, 10:11
ok
as i see here
http://doc.qt.digia.com/4.6/dialogs-extension.html
the qdialog in my case will be a widget
That's not a good tutorial. Start with the Addressbook tutorial.

robelle
2nd October 2012, 11:00
ok i make like that
i create new class "formulaire_segment"
"add_segment.h"




#ifndef FORMULAIRE_SEGMENT_H
#define FORMULAIRE_SEGMENT_H


#include <QWidget>
#include <QLineEdit>
#include <QtGui>

class formulaire_segment : public QWidget
{
Q_OBJECT

public :
formulaire_segment();

private:
QLineEdit *nom;
QLineEdit *nombre;
QLabel *nom_segment;
QLabel *nombre_points;
QPushButton *Bouton;
};

#endif

add_segment.cpp




#include"formulaire_segment.h"

formulaire_segment::formulaire_segment():QWidget()
{
setFixedSize(440, 140);
//creation des labels
nom_segment=new QLabel("nom_segment");
nombre_points=new QLabel("nombre_points");

//creation des edit
nom= new QLineEdit("", this);
nom->setGeometry(310, 15, 30, 30);

nombre= new QLineEdit("", this);
nombre->setGeometry(260, 55, 30, 30);
}


in the mainwindows


class formulaire_segment;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
public slots:
void showdialogue();


and


AddSegm = new QToolButton(page_13);
AddSegm->setObjectName(QString::fromUtf8("AddSegm"));
AddSegm->setGeometry(QRect(150, 9, 51, 31));
AddSegm->setText("Ajouter Segment");
connect(AddSegm, SIGNAL(clicked()),mQOgreWidget,SLOT(showdialogue() ));

//////////////////////////////*showdialogue slot///////////////////////////////////
void MainWindow::showdialogue()
{

formulaire_segment *formulaire=new formulaire_segment();

formulaire->show();


}



BUT when i clic on the button nothing happen i do not see the 2 window

boudie
2nd October 2012, 11:26
Change this:


connect(AddSegm, SIGNAL(clicked()),mQOgreWidget,SLOT(showdialogue() ));

to:


connect(AddSegm, SIGNAL(clicked()),this,SLOT(showdialogue()));

wysota
2nd October 2012, 11:50
ok i make like that
Please follow the tutorial. In particular, use layouts.

robelle
2nd October 2012, 11:52
thanks , it work now
but i do not see the labels

wysota
2nd October 2012, 12:04
Because you didn't use layouts.

robelle
2nd October 2012, 12:25
i added layout but nothing is happend


formulaire_segment::formulaire_segment():QWidget()
{
setFixedSize(440, 140);
//creation des labels
nom_segment=new QLabel("nom_segment");
nom_segment->setFont(QFont("Arial", 20));
nom_segment->setGeometry(20, 20, 440, 20);

nombre_points=new QLabel("nombre_points");
nombre_points->setFont(QFont("Arial", 12));
nombre_points->setGeometry(20, 60, 440, 20);

//creation des edit
nom= new QLineEdit("", this);
nom->setGeometry(310, 15, 30, 30);

nombre= new QLineEdit("", this);
nombre->setGeometry(260, 55, 30, 30);

QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nom_segment, 0, 0);
mainLayout->addWidget(nombre_point, 0, 1);
mainLayout->addWidget(nom, 1, 0);
mainLayout->addWidget(nombre, 1, 1);

wysota
2nd October 2012, 12:26
Please follow the tutorial I directed you to instead of blindly trying different things. Currently your layout configuration is incorrect.

robelle
2nd October 2012, 13:06
yes i forget :p

setLayout(mainLayout);
setWindowTitle(("formulaire"));

robelle
2nd October 2012, 17:37
it's me again
i have now problem with signal/slot

i add this in the file formulaire_segment.h


struct segm
{
QString name;
int number;
}S;

std::vector<segm> segment;


public slots :
void saveinfo();
signals:
void formulaire_remplie(std::vector<segm> segme);

and in the formulaire_segment.cpp


formulaire_segment::formulaire_segment():QWidget()
{
setFixedSize(440, 140);
//creation des labels
nom_segment=new QLabel("nom_segment");
nom_segment->setFont(QFont("Arial", 12));
nom_segment->setGeometry(20, 20, 440, 12);

nombre_points=new QLabel("nombre_points");
nombre_points->setFont(QFont("Arial", 12));
nombre_points->setGeometry(20, 60, 440, 20);

//creation des edit
nom= new QLineEdit("", this);
nom->setGeometry(310, 15, 30, 30);

nombre= new QDoubleSpinBox( this);
nombre->setGeometry(260, 55, 30, 30);
nombre->setRange(0, 4);
//
Bouton = new QToolButton(this);
Bouton->setObjectName("Ajouter");
Bouton->setGeometry(QRect(10, 10, 51, 31));
Bouton->setText("Ajouter");


QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nom_segment, 0, 0);
mainLayout->addWidget(/*nombre_points*/nom, 0,1);
mainLayout->addWidget(/*nom*/nombre_points, 1, 0);
mainLayout->addWidget(nombre, 1,1);
mainLayout->addWidget(Bouton, 2, 2);
setLayout(mainLayout);
setWindowTitle(tr("formulaire"));

connect(Bouton, SIGNAL(clicked()), this, SLOT( saveinfo()));


}

void formulaire_segment:: saveinfo()
{
segm segmente ;

segmente.name=nom->text();
segmente.number=nombre->value();
segment.push_back(segmente);
this->hide();
emit formulaire_remplie(segment);

}

in the mainwindow.h i added


struct segm
{
QString name;
int number;
}S;
public slots:
void showdialogue();
void formulaire_remplie(std::vector<segm> segme);

in the .cpp


connect(AddSegm, SIGNAL(clicked()),this,SLOT(showdialogue()));
/////////////////////
void MainWindow::showdialogue()
{

formulaire_segment *formulaire=new formulaire_segment();


formulaire->show();




}
void MainWindow::formulaire_remplie(std::vector<segm> segme)
{
printf ("je suis dans formulaire");

}

BUT when i run the program it does not enter to "formulaire_remplie"

EDIT

i adde this line in showdialogue()

connect(formulaire,SIGNAL (formulaire_remplie(std::vector<segm> segme)),this,SLOT(formulaire_remplie(std::vector<segm> segme)));
BUT i still when i run the program he does'nt enter to the function "formulaire_remplie"

Added after 52 minutes:

it work now i maked mistake in the connect

wysota
2nd October 2012, 17:37
I really suggest you do a couple of simple tutorials before doing anything serious.

You will solve your problem on your own if you can answer the following question: What are the (three) requirements that needs to be satisfied in order to use signals and slots within a class?

robelle
2nd October 2012, 17:38
thanks it work now

robelle
3rd October 2012, 08:22
she is me again :o

to save the information (name,number) i amke like that


void formulaire_segment:: saveinfo()
{
segm segmente ;

segmente.name=nom->text();
segmente.number=nombre->value();
segment.push_back(segmente);
this->hide();
emit formulaire_remplie(segment);
segment.clear();

}

i make segment.clear to return to the zero
but when i excute the Qdialogue for the seconde time i do not find it empty

wysota
3rd October 2012, 10:04
i make segment.clear to return to the zero
but when i excute the Qdialogue for the seconde time i do not find it empty

How does "segment" influence what is shown on the GUI? Do you change the values displayed in the UI based on the segment variable anywhere? I understand you may be a beginner programmer but before doing something you should first think how this something should be done, how it is done and how the two relate to each other.

robelle
3rd October 2012, 10:18
yes,
i found that the problem not with my signal
BUT
I forget to clear another vector in the slot

there is no problem now
thanks