PDA

View Full Version : Copying the content of int array to QString



vivekyuvan
26th September 2017, 05:47
Hi Friends

Help need to convert integer array To QString and emit the data to my slot


int a[10]={196,192,200,194,178,147,196,200,194,200};

I already tried this


char text[] = { '1', '2', '3', '4', '5', '\0' };
QString string(text);
qDebug()<<string;
emit Send_Data_Array_to_form(string);

above snippet work perfectly. But when i send integer array to QString the Receiver slot not properly receive my data i don know why. help me to resolve this issue.

this is my receiver slot


void MainWindow::Test_Array_Initialization(QString S_Data)
{
qDebug()<<"*****SIGNAL EMITED From My_signal_get_form1**********"<<endl;
qDebug()<<"data received"<<S_Data.size()<<S_Data;
}

Thanks in Advance.

Ginsengelf
26th September 2017, 07:13
Hi, your working snippet is basically a C-String, and QString has a constructor that uses a C-String as source.

To convert your integer array use a loop, call QString::number() for each of the array elements and append the result to your string.

Ginsengelf

ado130
26th September 2017, 11:29
For future, I recommend to use stl::vector (QVector) instead of typical array.