PDA

View Full Version : I am brand new and yes I am reading ALOT....



seerofsorrow
13th September 2017, 21:09
I finally got my ui portion to work but now I'm trying to figure out how to get the input of a text field to output to a string. Yes I've been looking at examples and everything but Im still completely confused. If someone could just send me an example I would really appreciate it.

ado130
13th September 2017, 21:45
You did not write if you use QLineEdit or QTextEdit, but e.g. for QLineEdit: http://doc.qt.io/qt-4.8/qlineedit.html#text-prop.
It would really help if you post some code that you tried.

seerofsorrow
13th September 2017, 23:43
So i have the basic code for a QWidget setup. Then in the UI i have a QLineEdit named versionText. I am attempting to make the input value in versionText a string so that I can reuse it again and then put it into an output file. That's what I'm having a hard time understanding.

What I have found so far hasn't worked and I'm trying to understand exactly what I need to setup in order to make that input into a string.

Added after 39 minutes:

This is the code I have for source.cpp(aka mainwindow.cpp):

#include "head.h"
#include "ui_Start.h"
#include <QString>
#include <QLineEdit>


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

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

void Class::on_caseNumberText_returnPressed()
{
caseNumberText->text().toStd
}


from the header file:

#ifndef HEAD_H
#define HEAD_H

#include <QMainWindow>
#include <QString>
#include <QLineEdit>

namespace Ui {
class Class;
}

class Class : public QMainWindow
{
Q_OBJECT

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



private:
Ui::Class *ui;
};

#endif // HEAD_H


In continues to state that returnPress isn't a member of class Class. And I have no idea how to fix this either but I was giving it a go.

ado130
14th September 2017, 05:20
I hope this will help https://www.youtube.com/watch?v=XauEGKUh5Xs
text() method returns a string (QString).

Ginsengelf
14th September 2017, 07:12
In continues to state that returnPress isn't a member of class Class. And I have no idea how to fix this either but I was giving it a go.
That's because you haven't added a declaration of your slot in your class. So from the compiler's point of view you have implemented a method that does not exist in the class.
In your class header file add


private slots:
void on_caseNumberText_returnPressed();


Ginsengelf

d_stranz
14th September 2017, 16:40
caseNumberText->text().toStd

And no idea what this is supposed to do. The line edit's text() method returns a QString, which doesn't have a method or member variable named "toStd". Even if it did, the statement you have written retrieves the text, converts it to something, and then immediately throws it away because you haven't assigned it to anything.

I think your reading should be expanded to include some basic C++ in addition to Qt.