View Full Version : How to use string from a class in other classes
elias174
13th July 2011, 03:24
hi, im new, i have this code
QString cuenta;
cuenta=ui->lineEdit->text();
this string its declared in public members in a Class names log, i need use this string in other classes, please help me, im novice in C++ and new in QT, thanks in advance, greetings
Santosh Reddy
13th July 2011, 04:02
Then you can post questions in General Programming Forum...
class LogClass {
public:
QString textString;
QString getTextString(void) const;
};
QString LogClass::getTextString(void) const
{
return textString;
}
function()
{
LogClass log;
// Both does the same
QString text_1 = log.getTextString();
QString text_2 = log.textString
}
elias174
13th July 2011, 04:40
thnks, i was try this but i have a error in the compilation, i did this:
MainWindow.cpp
#include "LogClass.h"
log login;
QString showme;
showme=login.cuenta;
ui->mostrarcuenta->setText(showtime);
the error its this:
login was not declarate in this scope
thnks
Santosh Reddy
13th July 2011, 04:44
show the log class definition, also I guess there should be more errors, post them too
elias174
13th July 2011, 04:55
ok, this its:
#ifndef LOG_H
#define LOG_H
#include <QMainWindow>
#include <QWidget>
#include "mainwindow.h"
#include <QSqlQuery>
#include <QKeyEvent>
namespace Ui {
class log;
}
class log : public QMainWindow
{
Q_OBJECT
public:
explicit log(QWidget *parent = 0);
QString cuenta;
~log();
private:
Ui::log *ui;
MainWindow m;
private slots:
// void funcion::keyPressEvent( QKeyEvent* );
void on_pushButton_clicked();
};
#endif // LOG_H
then, i call the Qstring cuenta so:
this code is located in mainwindow.cpp
log login;
QString showme;
showme= login.cuenta;
the compiler does not show other error
Santosh Reddy
13th July 2011, 05:23
first point, don't use a standard name like log (it can conflict with log() function in math.h), use a different class name.
next the error might related to Ui::log class, not ::log class (note the scope), try including "ui_log.h" (or whatever is the ui file name is) in mainwindow.cpp
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.