From QLineEdit Dialog to MainWindows
-
Hi!
I've been looking everywhere for 2 days now to understand this but still I dont get it.
I've a Dialog created with a .ui file and I have QLineEdit where I enter some input and I would like to take this input from the Dialog to the MainWindow.
How can I do it?I tried different code and this is the last one I tried (written in the Dialog)->
connect(this->ui->cp_PM, SIGNAL(textEdited(QString)), MainWindow, SLOT(ui->glmF->setText(QString)));This is a code I found online and works just fine but I need something similar from a Dialog to MainWindow ->
connect(this->ui->pmFV, SIGNAL(textEdited(QString)), ui->glmF, SLOT(setText(QString)));I tried looked at the doc in the Signal and Slot chapter, but it's not very clear
-
Hi!
I've been looking everywhere for 2 days now to understand this but still I dont get it.
I've a Dialog created with a .ui file and I have QLineEdit where I enter some input and I would like to take this input from the Dialog to the MainWindow.
How can I do it?I tried different code and this is the last one I tried (written in the Dialog)->
connect(this->ui->cp_PM, SIGNAL(textEdited(QString)), MainWindow, SLOT(ui->glmF->setText(QString)));This is a code I found online and works just fine but I need something similar from a Dialog to MainWindow ->
connect(this->ui->pmFV, SIGNAL(textEdited(QString)), ui->glmF, SLOT(setText(QString)));I tried looked at the doc in the Signal and Slot chapter, but it's not very clear
@aim0d said in From QLineEdit Dialog to MainWindows:
How can I do it?
Add a getter method to your dialog which returns the data you need. No need for signals/slots here.
// In MainWindow Dialog dlg; dlg.exec(); QString value = dlg.getResult(); // In Dialog QString Dialog::getResult() { return ui->pmFV->text(); } -
Hi!
I've been looking everywhere for 2 days now to understand this but still I dont get it.
I've a Dialog created with a .ui file and I have QLineEdit where I enter some input and I would like to take this input from the Dialog to the MainWindow.
How can I do it?I tried different code and this is the last one I tried (written in the Dialog)->
connect(this->ui->cp_PM, SIGNAL(textEdited(QString)), MainWindow, SLOT(ui->glmF->setText(QString)));This is a code I found online and works just fine but I need something similar from a Dialog to MainWindow ->
connect(this->ui->pmFV, SIGNAL(textEdited(QString)), ui->glmF, SLOT(setText(QString)));I tried looked at the doc in the Signal and Slot chapter, but it's not very clear
This post is deleted! -
@aim0d said in From QLineEdit Dialog to MainWindows:
How can I do it?
Add a getter method to your dialog which returns the data you need. No need for signals/slots here.
// In MainWindow Dialog dlg; dlg.exec(); QString value = dlg.getResult(); // In Dialog QString Dialog::getResult() { return ui->pmFV->text(); }@jsulm It worked, thanks!
Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
I tried via getValuePar():dialog.cpp
QString parametri::getValuePar() { QString pmFV = ui->pmFV->text(); QString glmF = ui->glmF->text(); QString icpF =ui->icpF->text(); QString gamEP =ui->gamEP->text(); QString icpEP = ui->icpEP->text(); return pmFV + glmF; } QString parametri::getResult() { return getValuePar(); }MainWindow,cpp
void MainWindow::on_parametri_clicked() { class parametri pd; pd.exec(); QString value = pd.getResult(); qDebug() << value; }When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
-
@jsulm It worked, thanks!
Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
I tried via getValuePar():dialog.cpp
QString parametri::getValuePar() { QString pmFV = ui->pmFV->text(); QString glmF = ui->glmF->text(); QString icpF =ui->icpF->text(); QString gamEP =ui->gamEP->text(); QString icpEP = ui->icpEP->text(); return pmFV + glmF; } QString parametri::getResult() { return getValuePar(); }MainWindow,cpp
void MainWindow::on_parametri_clicked() { class parametri pd; pd.exec(); QString value = pd.getResult(); qDebug() << value; }When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
@aim0d said in From QLineEdit Dialog to MainWindows:
When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
What do you expect? I mean - what should this do:
QString parametri::getValuePar() { ui->pmFV->text(); ui->glmF->text(); ui->icpF->text(); ui->gamEP->text(); }Please learn c++ basics.
-
@jsulm It worked, thanks!
Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
I tried via getValuePar():dialog.cpp
QString parametri::getValuePar() { QString pmFV = ui->pmFV->text(); QString glmF = ui->glmF->text(); QString icpF =ui->icpF->text(); QString gamEP =ui->gamEP->text(); QString icpEP = ui->icpEP->text(); return pmFV + glmF; } QString parametri::getResult() { return getValuePar(); }MainWindow,cpp
void MainWindow::on_parametri_clicked() { class parametri pd; pd.exec(); QString value = pd.getResult(); qDebug() << value; }When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
@aim0d said in From QLineEdit Dialog to MainWindows:
I'm actually have more QLineEdit value to transfer from Dialog to MW
Either create a getter method for each of them or create a structure where you put all these strings and implement a getter method which returns this struct.
-
@jsulm It worked, thanks!
Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
I tried via getValuePar():dialog.cpp
QString parametri::getValuePar() { QString pmFV = ui->pmFV->text(); QString glmF = ui->glmF->text(); QString icpF =ui->icpF->text(); QString gamEP =ui->gamEP->text(); QString icpEP = ui->icpEP->text(); return pmFV + glmF; } QString parametri::getResult() { return getValuePar(); }MainWindow,cpp
void MainWindow::on_parametri_clicked() { class parametri pd; pd.exec(); QString value = pd.getResult(); qDebug() << value; }When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
@aim0d said in From QLineEdit Dialog to MainWindows:
but crashed when I click the button to open the Dialog
I think it crashes here
QString value = pd.getResult();because your non void function has no return statement. You should have at least a warning about this in QtCreator.
-
@aim0d said in From QLineEdit Dialog to MainWindows:
When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
What do you expect? I mean - what should this do:
QString parametri::getValuePar() { ui->pmFV->text(); ui->glmF->text(); ui->icpF->text(); ui->gamEP->text(); }Please learn c++ basics.
@Christian-Ehrlicher I was trying to get every text for my QLineEdit; I wrote it like that just becuase I thought I have to wrote it like this to have the same result as the first answer i get.
What do you expect?
As I already said: I just want to get the texts from QLineEdit in my Dialog to my Main Window
-
@aim0d said in From QLineEdit Dialog to MainWindows:
but crashed when I click the button to open the Dialog
I think it crashes here
QString value = pd.getResult();because your non void function has no return statement. You should have at least a warning about this in QtCreator.
@J-Hilk
You should have at least a warning about this in QtCreator.
I dont, because my MainWindow start and when I try to open the Dialog the terminal just says it crashed. If I had a warning first I would see it and second my application woudnt start at all
-
@aim0d said in From QLineEdit Dialog to MainWindows:
I'm actually have more QLineEdit value to transfer from Dialog to MW
Either create a getter method for each of them or create a structure where you put all these strings and implement a getter method which returns this struct.
-
@jsulm It worked, thanks!
Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
I tried via getValuePar():dialog.cpp
QString parametri::getValuePar() { QString pmFV = ui->pmFV->text(); QString glmF = ui->glmF->text(); QString icpF =ui->icpF->text(); QString gamEP =ui->gamEP->text(); QString icpEP = ui->icpEP->text(); return pmFV + glmF; } QString parametri::getResult() { return getValuePar(); }MainWindow,cpp
void MainWindow::on_parametri_clicked() { class parametri pd; pd.exec(); QString value = pd.getResult(); qDebug() << value; }When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog
-
@aim0d I change it
but the result is the two values united like these are the values:
QString pmFV = ui->pmFV->text(123);
QString glmF = ui->glmF->text(78);and this is the output in qDebug() -> 12378
@aim0d said in From QLineEdit Dialog to MainWindows:
QString pmFV = ui->pmFV->text(123);
QString glmF = ui->glmF->text(78);This does not even compile...
How about some c++ basics before starting with Qt
I actually dont know how to do that. It the right way I mean.
See e.g QString::append()
-
@aim0d said in From QLineEdit Dialog to MainWindows:
QString pmFV = ui->pmFV->text(123);
QString glmF = ui->glmF->text(78);This does not even compile...
How about some c++ basics before starting with Qt
I actually dont know how to do that. It the right way I mean.
See e.g QString::append()
@Christian-Ehrlicher It gives me what I need in the wrong way
I dont have actual time to learn c++ in a right way; this is a work project and give me this stuff to do knowing I know very little of c++And I repeat, this give me the output I wrote in my last comment, but not in the format I need
This does not even compile...
it was and example to let you understand the output for god sake, it's not my actual code if you have to answer pls at least try to understan what I'm writing
-
@Christian-Ehrlicher It gives me what I need in the wrong way
I dont have actual time to learn c++ in a right way; this is a work project and give me this stuff to do knowing I know very little of c++And I repeat, this give me the output I wrote in my last comment, but not in the format I need
This does not even compile...
it was and example to let you understand the output for god sake, it's not my actual code if you have to answer pls at least try to understan what I'm writing
@aim0d said in From QLineEdit Dialog to MainWindows:
I dont have actual time to learn c++ in a right way;
Then you're wrong here.
And I repeat, this give me the output I wrote in my last comment, but not in the format I need
It does not compile since QLineEdit has not function text() which takes an integer.
I'm out here.
-
@Christian-Ehrlicher It gives me what I need in the wrong way
I dont have actual time to learn c++ in a right way; this is a work project and give me this stuff to do knowing I know very little of c++And I repeat, this give me the output I wrote in my last comment, but not in the format I need
This does not even compile...
it was and example to let you understand the output for god sake, it's not my actual code if you have to answer pls at least try to understan what I'm writing
@aim0d said in From QLineEdit Dialog to MainWindows:
I dont have actual time to learn c++ in a right way
Do you think it is better/more efficient to spend a lot of time in a forum to get help for issues you would not have if you would learn the basics of the programming language you're using? You should really reconsider your approach...
struct is one of the most basic things in C++:
struct Data { QString data1; QString data2; ... } Data parametri::getValuePar() { Data result; result.data1 = ui->pmFV->text(); result.data2 = ui->glmF->text(); ... return result; } -
@aim0d said in From QLineEdit Dialog to MainWindows:
I dont have actual time to learn c++ in a right way
Do you think it is better/more efficient to spend a lot of time in a forum to get help for issues you would not have if you would learn the basics of the programming language you're using? You should really reconsider your approach...
struct is one of the most basic things in C++:
struct Data { QString data1; QString data2; ... } Data parametri::getValuePar() { Data result; result.data1 = ui->pmFV->text(); result.data2 = ui->glmF->text(); ... return result; }Do you think it is better/more efficient to spend a lot of time in a forum to get help for issues you would not have if you would learn the basics of the programming language you're using? You should really reconsider your approach...
I know, but as I said it's a project my boss gives me with a deadline in a week and they know I have little experience in C++; so i'm stuck here trying to build something with what I know and I found online