qt-interest@trolltech.com
[Top] [All Lists]

Re: Convert QString to char*

Subject: Re: Convert QString to char*
From: "Harsimrat Thukral"
Date: Thu, 24 Mar 2005 14:08:06 -0500
When I changed QString::ascii() and latin1() it still has an unhadled 
exception....How can I change that C-String to a QString.....This is what I 
m trying to do....
this code is as follows.....I read the while loop ...put everything in an 
array....and then pass that array to next function to do some more 
stuff.....this thing is giving me hard time...pls suggest....
char **str_array = 0;

int size_of_array = 0;

while(sp != NULL)

{

if (sp == G.map[(G.find_node(G.map, source))])

{

ip1 = sp->name.c_str();

str_array = (char **) realloc(str_array, size_of_array * sizeof(char *));

str_array[size_of_array] = (char *) malloc(strlen(sp->name.c_str()));

strcpy(str_array[size_of_array], sp->name.c_str());

size_of_array++;

}

else

{


ip2 = sp->name.c_str();


str_array = (char **) realloc(str_array, size_of_array * sizeof(char *));

str_array[size_of_array] = (char *) malloc(strlen(sp->name.c_str()));

strcpy(str_array[size_of_array], sp->name.c_str());

size_of_array++;

}

sp = sp->next;


} // end of while


WPTopology(size_of_array);


} // end of Working Path Calculation



//*******************************************************************************//

// Deduct the Bandwidth Used

//*******************************************************************************//

void MNetmain::WPTopology(int array)

{

// Capacity provided by the user

QString capacity = m_MNetMW->lineEdit2->text().latin1();

char **mystr = 0;


QStringList WTopology(topology); // Copy the Topology


for( uint i(0); i < WTopology.count(); i++ )

{

QStringList line( QStringList::split( " ", WTopology[i], false ) );

QString ip1 = *line.at( 0 );

ip1 = ip1.stripWhiteSpace( );


for(int j=0; j<array; j++)

{

if(strcmp(mystr[j],ip1.ascii()) == 0)

{

QMessageBox::information(this,"ip1",ip1);

}

}


} // end of for statement


}



Thank You

Harsimrat Thukral

"Christopher Thompson" <chris@xxxxxxxxxxxxxxxxx> wrote in message 
news:200503241158.26715.chris@xxxxxxxxxxxxxxxxxxxx
> On March 24, 2005 11:55 am, Harsimrat Thukral wrote:
>> Hello all
>>
>> Is there any way to change QString to char*
>
> Yes, take a look at the QString::ascii() and QString::latin1() methods. 
> Note
> that in general, you probably want to use QStrings or C++ strings in your
> code, not the older C-style strings.
>
>> if(strcmp(mystr[j],ip1) == 0)    // Here I comparing the string so which
>> takes char*
>
> Additionally, you MAY find it faster to convert your other C-string to a
> QString and do the comparison that way.
>
> -- 
> chris@xxxxxxxxxxxxxxxxx, chris@xxxxxxxxxxxxx 

--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>