Results 1 to 3 of 3

Thread: QStringList

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QStringList

    Hello anyone,

    I have Qt-4.2.3 on Windows XP
    The problem is QStringList
    I want to read a line with string items in QStringList through a Dialog .
    I did this with QtSql and it works fine but i don't want to use QtSql.
    I want to use a file.

    mainwindow.cpp
    Qt Code:
    1. oid MainWindow::zoek()
    2. {
    3. zoekDialog dlg(this);
    4. if( dlg.exec() == QDialog::Accepted ) {
    5.  
    6. QString treksterkte, koeling, snijsnelheid, voedingpertand, snedediepte, snedebreedte,
    7.  
    8. QString materiaal = dlg.matComboBox->currentText();
    9. QString freestype = dlg.freesComboBox->currentText();
    10. QString diameter = dlg.diaComboBox->currentText();
    11. QString tand = dlg.tandComboBox->currentText();
    12. QString bewerking = dlg.bewerkComboBox->currentText();
    13.  
    14. QFile file("C:/Qt/Qt-prog/richtwaarden/frees.txt");
    15. if( !file.open(QFile::ReadOnly))
    16. return;
    17.  
    18. QTextStream stream( &file);
    19. QString line;
    20. do {
    21.  
    22. line = stream.readLine();
    23. if(!line.isEmpty())
    24. {
    25. QStringList frees = line.split('\t', QString::SkipEmptyParts);
    26. QStringList::iterator it = frees.begin();
    27. if(it != frees.end())
    28. {
    29. if ( *it == materiaal )
    30. leMateriaal->setText(*it); //put the text in the linedit.
    31. ++it;
    32. }
    33. }
    34. }while(!line.isEmpty());
    35.  
    36.  
    37. file.close();
    38. }
    To copy to clipboard, switch view to plain text mode 
    This works but he only find one string materiaal.
    I want to find all the string items wich i choose in the comboboxes in the zoekdialog.

    Thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList

    OK. What is the desired behavior when you put the same text in the line edit( lines 29&30).
    Have you verified the text file and see what is in it?
    What about if you print( with qDebug ) what readLine returns? What is the result of that?

    Regards

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QStringList

    Sorry for delay for reply i was on hollyday.

    first the frees.txt file have 11 string items on the row seperated with tabs.
    see example.
    Koolstofstaal 350-850 EC 5 3 Ja Contour frezen 80-100 0.015-0.030 max. 2xD <2.5
    Gereedschapstaal 800-1200 EC 8 3 Ja Gleuf frezen 80-100 0.015-0.030 max. 2xD <2.5
    These file will be updated with 600 rows.

    In my zoekDialog i have 5 comboboxes in each combobox different items.
    When i choose items i want to show the items in Mainwindow lineedits.
    example:
    combobox 1 = Koolstofstaal
    combobox 2 = EC
    combobox 3 = 5
    combobox 4 = 3
    combobox 5 = Contour Frezen
    The rest of the row in frees.txt must fill up in the other Mainwindow lineedits.

    The problem is the iterator on stringlist show only 1 string item.
    Normally i want to use in if 5 statements but the pick only 1 the first one
    See example.
    if ( mat == dlg.matComboBox->currentText() && frees == dlg.freesComboBox->currenText() && etc ... ) every statement must be true.

    see MainWindow.cpp
    Qt Code:
    1. void MainWindow::zoek()
    2. {
    3. zoekDialog dlg(this);
    4. if( dlg.exec() == QDialog::Accepted ) { // Open a Dialog with 5 Comboboxen filled with items.
    5.  
    6. QString treksterkte, koeling, voedingpertand, snijsnelheid, snedediepte, snedebreedte;
    7. QString mat = dlg.matComboBox->currentText(); //Choose a item in the combobox and put in the string mat.
    8. QString frees = dlg.freesComboBox->currentText();
    9. QString tand = dlg.tandComboBox->currentText();
    10. QString dia = dlg.diaComboBox->currentText();
    11. QString bewrk = dlg.bewerkComboBox->currentText();
    12.  
    13. QFile file("C:/Qt/Qt-prog/richtwaarden/frees.txt"); //Open the file with strings seperated with tabs.
    14. if( !file.open(QFile::ReadOnly))
    15. return;
    16.  
    17. QTextStream stream( &file);
    18. QString line;
    19. do {
    20.  
    21. line = stream.readLine();
    22. if(!line.isEmpty())
    23. {
    24. QStringList frees = line.split('\t', QString::SkipEmptyParts); // Make a Stringlist
    25. QListIterator<QString> i(frees); // Iterate over the Stringlist frees.
    26. while (i.hasNext())
    27. {
    28.  
    29. if ( mat == i.next()) // It search for that item in the Stringlist en put the item
    30. leMateriaal->setText( mat ); // in the Mainwindow Lineedit.
    31. if ( freestype == i.next())
    32. leFrees->setText( freestype ); // This don't work
    33. }
    34. }
    35. }while(!line.isEmpty());
    36.  
    37.  
    38. file.close();
    39. }
    To copy to clipboard, switch view to plain text mode 

    B.T.W. i did this with QtSql and QTSqlQuerry no problem works fine.
    see little example of code:
    Qt Code:
    1. void MainWindow::zoek()
    2. {
    3. zoekDialog dlg(this);
    4. if( dlg.exec() == QDialog::Accepted ) {
    5.  
    6. QString materiaal;
    7.  
    8. QSqlQuery query("SELECT * FROM frezen WHERE materiaal='" + dlg.matComboBox->currentText() + "'AND freesdiameter='" + dlg.diaComboBox->currentText() + "'AND freestype='" + dlg.freesComboBox->currentText() + "'AND aantaltanden='" + dlg.tandComboBox->currentText() + "'AND freesbewerking='" + dlg.bewerkComboBox->currentText() + "';");
    9. if (query.next())
    10. materiaal= query.value(0).toString();
    11. leMateriaal->setText(materiaal); QString treksterkte = query.value(1).toString();
    12. leTrek->setText(treksterkte);
    13. QString freestype = query.value(2).toString();
    14. leFrees->setText(freestype);
    15. QString freesdiameter = query.value(3).toString();
    16. leDiam->setText(freesdiameter);
    17. QString aantaltanden = query.value(4).toString();
    18. leAantal->setText(aantaltanden);
    19. QString koeling = query.value(5).toString();
    20. leKoeling->setText(koeling);
    21. QString freesbewerking = query.value(6).toString();
    22. leFreesb->setText(freesbewerking);
    23. QString snijsnelheid = query.value(7).toString();
    24. leSnijsnelheid->setText(snijsnelheid);
    25. QString voedingpertand = query.value(8).toString();
    26. leAanzet->setText(voedingpertand);
    27. QString snedediepte = query.value(9).toString();
    28. leSneded->setText(snedediepte);
    29. QString snedebreedte = query.value(10).toString();
    30. leSnedeb->setText(snedebreedte);
    To copy to clipboard, switch view to plain text mode 
    Maby i must stick with QTSql.

    Thaks in advance.

Similar Threads

  1. Translating a QStringList
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 18th January 2007, 12:06
  2. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 18:01
  3. QStringList with Signal/Slot
    By Sivert in forum Qt Programming
    Replies: 4
    Last Post: 3rd May 2006, 21:34
  4. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 21:48
  5. need help to classify some QStringList
    By patcito in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 22:24

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.