Results 1 to 10 of 10

Thread: Displaying data column into combobox

  1. #1
    Join Date
    Jan 2011
    Posts
    14
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Talking Displaying data column into combobox

    Hi........
    I'm new to Qt. in my application, i have a file which consist of columns with values and i want to show first column values into combobox list and also take duplicates out. and in second column of values i want to show minimum and maximum value in that column in a label. how to do it? my columns look like this:

    Station Ammonia
    1 6
    1 4
    1 7
    1 23
    2 5
    2
    2
    2
    2
    3
    3
    3
    3
    4
    4
    4

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Displaying data column into combobox

    Hi,

    If your file is a text file you can use:
    Qt Code:
    1. QFile file("in.txt");
    2. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    3. return;
    4.  
    5. while (!file.atEnd()) {
    6. QByteArray line = file.readLine();
    7. process_line(line);
    8. }
    To copy to clipboard, switch view to plain text mode 

    process_line is your process that moves a item of the file into the combo taking ignoring the duplicates.

    If you need more than one column in the comboBox. You can use a QTableWidget to store the values and then set the QTableWidget to the combo by using setView ( QAbstractItemView * itemView ). The documentation on QTableWidget shows you how to add items to a QTableWidget.

    You can see this thread for more information http://www.qtforum.org/article/33282...ns-solved.html

    Carlos.

  3. #3
    Join Date
    Jan 2011
    Posts
    14
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Displaying data column into combobox

    Hi...... nw my prroblem is
    i my application i am using comboBox to display a list.

    now the problem is that when i click the combo box then the no of items in the combo box list insted of displaying in a scroll window are displayed all at a time and since i am having a big list, the display covers most part of my screen........

    'Station' column is too large
    but i want minimun and maximum value of column 'Ammonia '

    How to solve this problem???????????

  4. #4
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Displaying data column into combobox

    Hi,

    Can you post an screen shot?

    Check setMaxVisibleItems()

    Carlos.

  5. #5
    Join Date
    Jan 2011
    Posts
    14
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Displaying data column into combobox

    Can u tell me how to read minimum and maximum values from column Ammonia and show it on label?

    How to slove this problem????????

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Displaying data column into combobox

    Read the file line-by-line, then for each line : split the line into two parts separated by white space - now if you get two values, update your current max and min values according to second value from split.
    Some useful methods:
    QString::split
    QString::toInt
    Then convert values to string : QString::number
    or use this one
    QString::arg
    and set text on label:
    QLabel::setText
    If you'll have any problems with implementation we'll be happy to help you (at least I will), but first you need to try yourself.

  7. #7
    Join Date
    Jan 2011
    Posts
    14
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Displaying data column into combobox

    i'm sending my full code and attached UI of the code which i have done. help me out. b123.txt is my column data file and jgj.txt is what i select in the UI.


    #include "profile.h"
    #include "ui_profile.h"
    #include<QTextStream>
    #include<QFile>

    QString a1[50];

    int line3=1;
    int l3,j1;
    QStringList r;
    QStringList dep;

    Profile::Profile(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Profile)
    {
    ui->setupUi(this);
    ui->comboBox->clear();
    QFile file("b123.txt");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    return;
    QTextStream in(&file);
    QString s;
    while(!in.atEnd())
    {s=in.readLine();
    if(line3==1)
    {

    QStringList l=s.split("\t");
    l3=l.size();
    for(int i=0;i<l3;i++)
    {


    QString q=l.at(i);
    a1[i]=q;
    // out1<<a[i]<<"\t";
    }


    }

    line3++;
    }

    in.seek(0);
    line3=1;
    for(j1=0;j1<l3;j1++)
    {
    if(a1[j1]=="Station")
    {
    break;
    }
    }
    while(!in.atEnd())
    {s=in.readLine();
    if(line3!=1)
    {

    QStringList l=s.split("\t");
    l3=l.size();

    QString q=l.at(j1);
    r.append(q);

    }

    line3++;
    }

    in.seek(0);
    line3=1;
    //min Depth
    for(j1=0;j1<l3;j1++)
    {
    if(a1[j1]=="Depth")
    {
    break;
    }
    }
    while(!in.atEnd())
    {s=in.readLine();
    if(line3!=1)
    {

    QStringList l=s.split("\t");
    l3=l.size();

    QString q=l.at(j1);
    dep.append(q);
    // out1<<a[i]<<"\t";


    }

    line3++;
    }
    dep.removeDuplicates();
    dep.sort();


    ui->lineEdit->setText(dep.takeFirst());

    file.close();

    r.removeDuplicates();
    r.sort();
    for(int k=0;k<r.size();k++)
    {
    ui->comboBox->addItem(r[k]);
    }

    for(j1=0;j1<l3;j1++)
    {
    if(a1[j1]=="Depth")
    {
    break;
    }
    }


    for(int k=j1;k<l3;k++)
    {

    ui->comboBox_3->addItem(a1[k]);

    }

    }
    Attached Images Attached Images
    Attached Files Attached Files

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Displaying data column into combobox

    First of all, please modify your post and add [CODE] tags, because the code you've posted is hard to read.
    What exactly is your problem now ? I think you want to do too many things at once. Start by creating a method that will parse your file and extract min and max values from second column. Don't worry about ui for now, just use qDebug() to test it. Then you can think about displaying the result in ui ( when you'll know that its correct ).

  9. #9
    Join Date
    Jan 2011
    Posts
    14
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Displaying data column into combobox

    i'm reading from b123.txt file
    first i want to make a file selected station with corresponding depth values and selected parameters from UI.
    Secondly, i want to show from that file min and max of depth values on ui. help me to solve the problem
    regards
    deck99

    Qt Code:
    1. #include "profile.h"
    2. #include "ui_profile.h"
    3. #include<QTextStream>
    4. #include<QFile>
    5.  
    6. QString a1[50];
    7.  
    8. int line3=1;
    9. int l3,j1;
    10.  
    11. Profile::Profile(QWidget *parent) :
    12. QDialog(parent),
    13. ui(new Ui::Profile)
    14. {
    15. ui->setupUi(this);
    16. ui->comboBox->clear();
    17. QFile file("b123.txt");
    18. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    19. return;
    20. QTextStream in(&file);
    21. while(!in.atEnd())
    22. {s=in.readLine();
    23. if(line3==1)
    24. {
    25.  
    26. QStringList l=s.split("\t");
    27. l3=l.size();
    28. for(int i=0;i<l3;i++)
    29. {
    30.  
    31.  
    32. QString q=l.at(i);
    33. a1[i]=q;
    34. // out1<<a[i]<<"\t";
    35. }
    36.  
    37.  
    38. }
    39.  
    40. line3++;
    41. }
    42.  
    43. in.seek(0);
    44. line3=1;
    45. for(j1=0;j1<l3;j1++)
    46. {
    47. if(a1[j1]=="Station")
    48. {
    49. break;
    50. }
    51. }
    52. while(!in.atEnd())
    53. {s=in.readLine();
    54. if(line3!=1)
    55. {
    56.  
    57. QStringList l=s.split("\t");
    58. l3=l.size();
    59.  
    60. QString q=l.at(j1);
    61. r.append(q);
    62.  
    63. }
    64.  
    65. line3++;
    66. }
    67.  
    68. in.seek(0);
    69. line3=1;
    70. //min Depth
    71. for(j1=0;j1<l3;j1++)
    72. {
    73. if(a1[j1]=="Depth")
    74. {
    75. break;
    76. }
    77. }
    78. while(!in.atEnd())
    79. {s=in.readLine();
    80. if(line3!=1)
    81. {
    82.  
    83. QStringList l=s.split("\t");
    84. l3=l.size();
    85.  
    86. QString q=l.at(j1);
    87. dep.append(q);
    88. // out1<<a[i]<<"\t";
    89.  
    90.  
    91. }
    92.  
    93. line3++;
    94. }
    95. dep.removeDuplicates();
    96. dep.sort();
    97.  
    98.  
    99. ui->lineEdit->setText(dep.takeFirst());
    100.  
    101. file.close();
    102.  
    103. r.removeDuplicates();
    104. r.sort();
    105. for(int k=0;k<r.size();k++)
    106. {
    107. ui->comboBox->addItem(r[k]);
    108. }
    109.  
    110. for(j1=0;j1<l3;j1++)
    111. {
    112. if(a1[j1]=="Depth")
    113. {
    114. break;
    115. }
    116. }
    117.  
    118.  
    119. for(int k=j1;k<l3;k++)
    120. {
    121.  
    122. ui->comboBox_3->addItem(a1[k]);
    123.  
    124. }
    125.  
    126. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by deck99; 8th March 2011 at 12:58.

  10. #10
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Displaying data column into combobox

    After looking at your code I don't know what it does, it's very enigmatic - such variable names a1, l3, j1, r doesn't really help others to understand what you mean.
    Provide more detailed explanation of your current algorithm, because now I don't know how could I help you.

Similar Threads

  1. Column/Row no of ComboBox Widget in Table
    By ankurjain in forum Qt Programming
    Replies: 13
    Last Post: 6th December 2011, 11:03
  2. Replies: 4
    Last Post: 28th August 2010, 13:17
  3. member function to read data from a combobox
    By babygal in forum Qt Programming
    Replies: 2
    Last Post: 17th August 2010, 11:44
  4. Displaying YUV data through Phonon
    By heminm in forum Qt Programming
    Replies: 0
    Last Post: 10th October 2009, 16:16
  5. Problem in displaying the ComboBox list
    By raghvendramisra in forum Qt Tools
    Replies: 4
    Last Post: 28th February 2008, 13:25

Tags for this Thread

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.