Results 1 to 3 of 3

Thread: QStringlist problem

  1. #1
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Question QStringlist problem

    Hello
    I am using QStringlist in one of my class which return the list to other class for the future use.
    Qt Code:
    1. class test
    2. {
    3. QStringList test:: getDeviceInfoList()
    4. {
    5.  
    6. QStringList portList;
    7.  
    8.  
    9. if (numDevs > 0)
    10. {
    11. // allocate storage for list based on numDevs
    12. devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
    13.  
    14. // get the device information list
    15. ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs);
    16.  
    17. if (ftStatus == FT_OK)
    18. {
    19. for (int i = 0; i < numDevs; i++)
    20. {
    21.  
    22. portList.append(QString(devInfo[i].SerialNumber));
    23. }
    24. }
    25. return portList;
    26. }
    27.  
    28. }
    29. }
    30.  
    31. class test2
    32. {
    33. bool test2::connect()
    34. {
    35. bool serialPortResponding = false;
    36.  
    37. if (m_D2xxport->PortConfiguration( m_D2xxport->getDeviceInfoList().at(0).toStdString().c_str()));
    38. {
    39. serialPortResponding = true;
    40. }
    41. else
    42. {
    43. serialPortResponding = false;
    44.  
    45. }
    46.  
    47. return serialPortResponding;
    48.  
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 
    The above code works fine if my portList contain some data.Some time it happens my portList does not contain any data in the case i get runtime error
    on position
    Qt Code:
    1. if (m_D2xxport->PortConfiguration( m_D2xxport->getDeviceInfoList().at(0).toStdString().c_str()));
    To copy to clipboard, switch view to plain text mode 
    I want to send null if my portList is empty or if list is empty send null if full then send portList .
    QStringlist always show compile time error if i send Null or 0.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStringlist problem

    There is a return missing in your getDeviceInfoList(), when the if condition is not met.
    Just return QStringList()

    And you need to check the returned list before attempting access by index.

    Something like
    Qt Code:
    1. const QStringList deviceInfos = m_D2xxport->getDeviceInfoList();
    2. if (!deviceInfos.isEmpty() && m_D2xxport->PortConfiguration( deviceInfos.at(0).... )
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    anh5kor (28th November 2014)

  4. #3
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QStringlist problem

    Thanks anda_skoa for the solution .it's working for my code...

Similar Threads

  1. qDebug / qStringList - Problem
    By EMKAH in forum Newbie
    Replies: 5
    Last Post: 19th November 2012, 16:50
  2. QStringList problem :/
    By hakermania in forum Qt Programming
    Replies: 9
    Last Post: 17th August 2010, 13:55
  3. qstringlist problem
    By stella1016 in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2009, 09:16
  4. problem clear QStringList
    By jaca in forum Newbie
    Replies: 4
    Last Post: 30th May 2008, 16:10
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

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.