LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2003, 05:54 AM   #1
GYRO
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Rep: Reputation: 0
Unhappy Problems with QString !!!


I am new to Linux and QT, recently installed Red-hat 9 and am having problems with QString. Ive been through the QT Designer - Quick start - tutorials everything compiles and working fine but can only find examples of making QString variables with a string set when declared that doesn't change.

I wanted to read a string in from a file then displays it in a QLineedit, then turn the string round, so it is back to front and displays it in another line QLineedit.

I have got a simple c program to do this but displays the string at the command line instead, using ( char ) arrays and ( FILE ).

I hadn’t used QT before and tried to use the equivalent of:

char string[50] = "a string";

myLineedit->setText(string);

and I got an error saying it needs a ( const QString* ) or something like that, so I tried:

QString string[50] = "a string";

I got more errors, but it let me do:

QString string = "a string";

I compiled and it worked, but once I’d done that. I couldn’t find a way to swap the string round so it was back to front i.e. "gnirts a", except by a separate ( char ), is there a way?

I tried:

char temp[50] = "my string";
QString string = temp;

But again I got errors, so I looked on the Internet an found I could use the

mylineedit->setText(QString("%1").arg( temp ) ):

That worked as long as temp wasn’t an array.

Is there any way you can use QString like a ( char ) array?
Or sending an array to setText?
Or any other way of changing a string round char by char you could think of? All suggestions and help are welcome.

Thanks for any help

Last edited by GYRO; 11-18-2003 at 08:45 AM.
 
Old 11-17-2003, 08:00 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hello,

you have told us what you want to
do ... what is your QString related
problem?

Cheers,
Tink
 
Old 11-18-2003, 06:43 AM   #3
GYRO
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Original Poster
Rep: Reputation: 0
all messages are welcome

Last edited by GYRO; 11-18-2003 at 08:49 AM.
 
Old 11-18-2003, 02:44 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
That's rather generous but won't help
us in trying to help you....



Cheers,
Tink
 
Old 11-24-2003, 06:34 AM   #5
GYRO
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Original Poster
Rep: Reputation: 0
i solved half the problem and found a way of shortening my problem to a line:

i can convert from char[] to QString by:

char string[] = "hi";

MyLineEdit->setText( QString( "%s" ).arg( string ) );

ill i want to do now is convert from QString back to char[], So i can put back in that array whatever is in a QLineedit, i found the .ascii() and .latin1() functions but they dont seem to work on char arrays through:

MyLineEdit->text();

can any one help now, please?

Last edited by GYRO; 11-25-2003 at 06:19 AM.
 
Old 11-27-2003, 03:33 AM   #6
GYRO
LQ Newbie
 
Registered: Nov 2003
Posts: 6

Original Poster
Rep: Reputation: 0
SOLVED

I Solved the problem.

with QByteArray and QCString:

QString qstring = "solved";

QByteArray qarray = QCString( qstring );

or

QByteArray qarray = QCString( mylineedit->Text().Latin1() );

then as before on the other end.

mylineedit->setText("%1").args(qarray);

Thanks anyway.

P.S if anyone wants more information on QString / QCString / QByteArray go here




Last edited by GYRO; 11-27-2003 at 03:38 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
type cast from int to QString spoody_goon Programming 2 05-24-2005 06:14 AM
Ethernet Adsl Modem Driver Problems And Install Problems... akhilnair Linux - Hardware 12 11-28-2004 08:19 AM
Problems with OSS while trying to avoid problems in ALSA (scratchy sound) GT_Onizuka Linux - General 1 02-05-2004 11:55 PM
Problems, problems, problems. Lets start with the soundcard Kre8ive Linux - Newbie 5 08-07-2003 01:20 AM
Problems, problems, problems. Lets start with the ES 1868 AudioDrive Kre8ive Linux - Newbie 1 08-06-2003 07:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration