Results 1 to 3 of 3

Thread: Copying the content of int array to QString

  1. #1
    Join Date
    Jul 2017
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Copying the content of int array to QString

    Hi Friends

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

    Qt Code:
    1. int a[10]={196,192,200,194,178,147,196,200,194,200};
    To copy to clipboard, switch view to plain text mode 

    I already tried this

    Qt Code:
    1. char text[] = { '1', '2', '3', '4', '5', '\0' };
    2. QString string(text);
    3. qDebug()<<string;
    4. emit Send_Data_Array_to_form(string);
    To copy to clipboard, switch view to plain text mode 
    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

    Qt Code:
    1. void MainWindow::Test_Array_Initialization(QString S_Data)
    2. {
    3. qDebug()<<"*****SIGNAL EMITED From My_signal_get_form1**********"<<endl;
    4. qDebug()<<"data received"<<S_Data.size()<<S_Data;
    5. }
    To copy to clipboard, switch view to plain text mode 
    Thanks in Advance.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Copying the content of int array to QString

    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

  3. The following user says thank you to Ginsengelf for this useful post:

    vivekyuvan (27th September 2017)

  4. #3
    Join Date
    Jan 2017
    Posts
    58
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Copying the content of int array to QString

    For future, I recommend to use stl::vector (QVector) instead of typical array.

  5. The following user says thank you to ado130 for this useful post:

    vivekyuvan (27th September 2017)

Similar Threads

  1. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  2. Using an array and QString contains
    By TomJoad in forum Newbie
    Replies: 8
    Last Post: 12th April 2011, 05:31
  3. read ini file content and save into array
    By cooper in forum Newbie
    Replies: 8
    Last Post: 14th March 2011, 21:33
  4. Copying a pointer to a static 2D array
    By Cruz in forum Newbie
    Replies: 2
    Last Post: 11th April 2010, 16:05
  5. how to copy QString content into array
    By eric in forum Qt Programming
    Replies: 12
    Last Post: 14th November 2007, 23:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.