Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: How to store QSlider position Value into .txt file?

  1. #21
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to store QSlider position Value into .txt file?

    Quote Originally Posted by stampede View Post
    Qt Code:
    1. hsv.writeTextElement("HUE LOW",h_slide1);
    To copy to clipboard, switch view to plain text mode 
    second argument to "writeTextElement" should be a string, not an integer:
    Qt Code:
    1. hsv.writeTextElement("HUE LOW",QString::number(h_slide1));
    To copy to clipboard, switch view to plain text mode 
    Hi Stampede

    thank you for your valuable help,

    There is many to change, is there any fast method to change them efficiently?

  2. #22
    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: How to store QSlider position Value into .txt file?

    There is many to change, is there any fast method to change them efficiently?
    Is the int to string conversion slowing down your application ?

  3. #23
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to store QSlider position Value into .txt file?

    No, but i am porting Visual studio code to QT, there is alot, so i think if there is another way to change it? haha

    after i change to QString, How can i change it back to int?? QString::setNum() ?


    Added after 15 minutes:


    Qt Code:
    1. QXmlStreamReader hsv(&valueHSV);
    2. hsv.readNext();
    3. while(!hsv.atEnd())
    4. {
    5. if(hsv.isStartElement())
    6. {
    7. if(hsv.name()=="HSV")
    8. {
    9. if(hsv.name()=="HUE LOW")
    10.  
    11. ui->hueSlide1->setValue(QString::toInt(hsv.readElementText()));
    12. }
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    There is error if i do like this,
    please advise
    Last edited by YDYD; 2nd July 2014 at 13:18.

  4. #24
    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: How to store QSlider position Value into .txt file?

    toInt() is not a static method, you call it on a QString object.

    Qt Code:
    1. ui->hueSlide1->setValue(hsv.readElementText().toInt());
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    YDYD (3rd July 2014)

  6. #25
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: How to store QSlider position Value into .txt file?

    Thanks for advise! =)

  7. #26
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to store QSlider position Value into .txt file?

    Hi all, here is an update...
    I cant read through my xml file,
    It stuck at
    qDebug<<"reading"; part
    continuos printing reading for output...
    Please help check if there is any error.


    This is saving to xml file, working fine
    Qt Code:
    1. void Dialog::saveValue()
    2. {
    3. int h_slide1 = ui->hueSlide1->value();
    4. int h_slide2 = ui->hueSlide2->value();
    5. int s_slide1 = ui->satSlide1->value();
    6. int s_slide2 = ui->satSlide2->value();
    7. int l_slide1 = ui->lumSlide1->value();
    8. int l_slide2 = ui->lumSlide2->value();
    9. QFile valueHSV("/home/pi/valueHSV/hsv.xml");
    10. if(!valueHSV.open(QIODevice::WriteOnly|QIODevice::Text))
    11. {
    12. qDebug() << "cannot open file for writing"<<endl;
    13. return;
    14. }
    15. QXmlStreamWriter hsv(&valueHSV);
    16. hsv.setAutoFormatting(true);
    17. hsv.writeStartDocument();
    18. hsv.writeStartElement("HSV");
    19. hsv.writeTextElement("HUE LOW",QString::number(h_slide1));
    20. hsv.writeTextElement("HUE HIGH",QString::number(h_slide2));
    21. hsv.writeTextElement("SAT LOW",QString::number(s_slide1));
    22. hsv.writeTextElement("SAT HIGH",QString::number(s_slide2));
    23. hsv.writeTextElement("LUM LOW",QString::number(l_slide1));
    24. hsv.writeTextElement("LUM HIGH",QString::number(l_slide2));
    25. hsv.writeEndElement();
    26. hsv.writeEndDocument();
    27. valueHSV.close();
    28.  
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    this is reading from xml part...
    Qt Code:
    1. void Dialog::loadValue()
    2. {
    3. //QStringList list;
    4. QFile valueHSV("/home/pi/valueHSV/hsv.xml");
    5. if(!valueHSV.open(QIODevice::ReadOnly|QIODevice::Text))
    6. {
    7. qDebug() << "cannot open file for reading"<<endl;
    8. return;
    9. }
    10. else
    11. {
    12. QXmlStreamReader hsv(&valueHSV);
    13. while(!hsv.atEnd())
    14. {qDebug()<<"reading";
    15. if(hsv.isStartElement())
    16. {
    17. qDebug()<<"here";
    18. if(hsv.name()=="HSV")
    19. {qDebug()<<"now";
    20. if(hsv.name()=="HUE LOW")
    21. {
    22. ui->hueSlide1->setValue(hsv.readElementText().toInt());
    23. qDebug()<<"1";
    24. }
    25. if(hsv.name()=="HUE HIGH")
    26. {
    27. ui->hueSlide2->setValue(hsv.readElementText().toInt());
    28. }
    29. if(hsv.name()=="SAT LOW")
    30. {
    31. ui->satSlide1->setValue(hsv.readElementText().toInt());
    32. }
    33. if(hsv.name()=="SAT HIGH")
    34. {
    35. ui->satSlide2->setValue(hsv.readElementText().toInt());
    36. }
    37. if(hsv.name()=="LUM LOW")
    38. {
    39. ui->lumSlide1->setValue(hsv.readElementText().toInt());
    40. }
    41. if(hsv.name()=="LUM HIGH")
    42. {
    43. ui->lumSlide2->setValue(hsv.readElementText().toInt());
    44. }
    45. }
    46.  
    47. }
    48. }
    49. }valueHSV.close();
    50.  
    51. }
    To copy to clipboard, switch view to plain text mode 

    Please advise.

    Thanks in advance
    Best Regards
    YDYD

  8. #27
    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: How to store QSlider position Value into .txt file?

    Your reading code is not doing any reading

    You need to advance in the stream by telling the stream reader to read.
    E.g. calling readNext() or in you case probably easier just calling readNextStartElement()

    Cheers,
    _

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

    YDYD (3rd July 2014)

Similar Threads

  1. Replies: 4
    Last Post: 1st December 2011, 20:53
  2. Secure way to store passwords in settings file
    By Alir3z4 in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2011, 13:27
  3. QSlider : How to hint current position value ?
    By andre_teprom in forum Newbie
    Replies: 2
    Last Post: 10th August 2011, 02:19
  4. read a .txt file and store it in a double array
    By fatecasino in forum Newbie
    Replies: 5
    Last Post: 3rd December 2010, 21:13
  5. initial position of a QSlider
    By franco.amato in forum Qt Programming
    Replies: 9
    Last Post: 24th September 2008, 19:37

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.