Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, December 2006
[Fwd: RE: Writing to a file]


Message 1 in thread

Wrong address, this one was meant to go here: qt-interest@xxxxxxxxxxxxx

Cheers, Oliver

p.s. I don't answer questions sent in private, sorry

-------- Original-Nachricht --------
Betreff: RE: Writing to a file
Datum: Thu, 28 Dec 2006 11:19:22 -0500
Von: Housman, Roger W. <housmanrw@xxxxxxxx>
An: Till Oliver Knoll <oliver.knoll@xxxxxxxxxxx>

Do you know how save the info from a QLineEdit?  Sorry, I wasn't
specific with my question.  I am fairly new to Qt and this is my first
try at writing to a file.  I am trying to take the info entered into a
QLineEdit box and write it to a file.  I can create and write to the
file, but it is writing the memory address from the QLineEdit instead of
the value store in it.

Here is my code for it:

//mapDialog.cpp

#include <QtGui>

#include "mapDialog.h"

QFile file("map.dat");

mapDialog::mapDialog(QWidget *parent)
    : QDialog(parent)
{
	setupUi(this);

	connect(beginButton, SIGNAL(clicked()), this,
SLOT(beginButton_clicked()));

}


//save info to map.dat when clicked
void mapDialog::beginButton_clicked()
{
    file.open(QIODevice::WriteOnly);
	
    QTextStream out(&file);
	out << numRooms;
}

//mapDialog.h

#ifndef MAPDIALOG_H
#define MAPDIALOG_H

#include <QDialog>

#include "ui_mapDialog.h"

class mapDialog : public QDialog, public Ui::mapForm
{
    	Q_OBJECT

public:
	mapDialog(QWidget *parent = 0);

private slots:
        void beginButton_clicked();
};

#endif

Thanks,
Roger


-----Original Message-----
From: Till Oliver Knoll [mailto:oliver.knoll@xxxxxxxxxxx]
Sent: Thursday, December 28, 2006 10:20 AM
To: Qt Interest List
Subject: Re: Writing to a file

Housman, Roger W. schrieb:
> 
> I am trying to write the info stored in a variable to a file.  How do 
> I get Qt to write the value stored in the variable instead of the 
> memory address of the variable to the file?

Does that work:

  int   value = 42;
  QFile file ("c:\\temp\\test.txt");

  if (file.open (QIODevice::WriteOnly | QIODevice::Text) == true) {
    QTextStream out (&file);
    out << "My value: " << value << "\n";
    file.close();
  }

Cheers, Oliver

--
 [ signature omitted ] 

Message 2 in thread

Till Oliver Knoll wrote:
> Wrong address, this one was meant to go here: qt-interest@xxxxxxxxxxxxx
> 
> Cheers, Oliver
> 
> p.s. I don't answer questions sent in private, sorry
> 
> -------- Original-Nachricht --------
> Betreff: RE: Writing to a file
> Datum: Thu, 28 Dec 2006 11:19:22 -0500
> Von: Housman, Roger W. <housmanrw@xxxxxxxx>
> An: Till Oliver Knoll <oliver.knoll@xxxxxxxxxxx>
> 
> Do you know how save the info from a QLineEdit?  Sorry, I wasn't
> specific with my question.  I am fairly new to Qt and this is my first
> try at writing to a file.  I am trying to take the info entered into a
> QLineEdit box and write it to a file.  I can create and write to the
> file, but it is writing the memory address from the QLineEdit instead of
> the value store in it.
> 
> Here is my code for it:
> 
> //mapDialog.cpp
> 
> #include <QtGui>
> 
> #include "mapDialog.h"
> 
> QFile file("map.dat");
> 
> mapDialog::mapDialog(QWidget *parent)
>     : QDialog(parent)
> {
> 	setupUi(this);
> 
> 	connect(beginButton, SIGNAL(clicked()), this,
> SLOT(beginButton_clicked()));
> 
> }
> 
> 
> //save info to map.dat when clicked
> void mapDialog::beginButton_clicked()
> {
>     file.open(QIODevice::WriteOnly);
> 	
>     QTextStream out(&file);
> 	out << numRooms;
> }
> 
> //mapDialog.h
> 
> #ifndef MAPDIALOG_H
> #define MAPDIALOG_H
> 
> #include <QDialog>
> 
> #include "ui_mapDialog.h"
> 
> class mapDialog : public QDialog, public Ui::mapForm
> {
>     	Q_OBJECT
> 
> public:
> 	mapDialog(QWidget *parent = 0);
> 
> private slots:
>         void beginButton_clicked();
> };
> 
> #endif
> 
> Thanks,
> Roger
> 
> 
> -----Original Message-----
> From: Till Oliver Knoll [mailto:oliver.knoll@xxxxxxxxxxx]
> Sent: Thursday, December 28, 2006 10:20 AM
> To: Qt Interest List
> Subject: Re: Writing to a file
> 
> Housman, Roger W. schrieb:
>> I am trying to write the info stored in a variable to a file.  How do 
>> I get Qt to write the value stored in the variable instead of the 
>> memory address of the variable to the file?
> 
> Does that work:
> 
>   int   value = 42;
>   QFile file ("c:\\temp\\test.txt");
> 
>   if (file.open (QIODevice::WriteOnly | QIODevice::Text) == true) {
>     QTextStream out (&file);
>     out << "My value: " << value << "\n";
>     file.close();
>   }
> 
> Cheers, Oliver
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
> 
intersting post

--
 [ signature omitted ] 

Message 3 in thread

> Do you know how save the info from a QLineEdit?  Sorry, I wasn't
> specific with my question.  I am fairly new to Qt and this is my first
> try at writing to a file.  I am trying to take the info entered into a
> QLineEdit box and write it to a file.  I can create and write to the
> file, but it is writing the memory address from the QLineEdit instead of
> the value store in it.
>
> Here is my code for it:
>
>
> //save info to map.dat when clicked
> void mapDialog::beginButton_clicked()
> {
>     file.open(QIODevice::WriteOnly);
> 	
>     QTextStream out(&file);
> 	out << numRooms;
> }
>   
What is 'numRooms'? If it's a pointer to the QLineEdit widget itself, as 
I suspect, then
that's exactly what you'd expect to happen.

You probably really meant

	out << numRooms->text();

to write the actual text the lineedit contains - see the QLineEdit docs.

- Keith



--
 [ signature omitted ]