Results 1 to 16 of 16

Thread: Qt Function doesn't work And there is no error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt Function doesn't work And there is no error

    The function ( QString getCreationDate() const ) doesn't return anything is it bugged or am i missing something obvious?

    although there is another function that almost do the same thing but for another variable and it works like charm...
    note* the compiler doesn't output any error. it just don't behave as expected!

    Qt Code:
    1. //class counter (where the function is defined)
    2. Counter( QString name,int start = 0,bool firstTime = true,QDate CreationTime = QDate::currentDate())
    3. :
    4. ClickTimes(start),
    5. name(name),
    6. firstTime(firstTime),
    7. lastDate(QDate::currentDate()),
    8. CreationTime(CreationTime)
    9. {}
    10.  
    11. QString getDate() const
    12. {
    13. return lastDate.toString("dd/MM/yyyy"); //this one works perfectly
    14. }
    15.  
    16. QString getCreationDate() const
    17. {
    18. return CreationTime.toString("dd/MM/yyyy"); //this one don't
    19. }
    20. /*---------------------------------------------------------*/
    21. //MainWindow.cpp
    22.  
    23. //here is where the adding (creating the counter happens)
    24. void MainWindow::addItemToList()
    25. {
    26. QString text2 = ui->inputBox_2->text();
    27.  
    28. //setting the model (some deleted code just to be on point)
    29.  
    30. //model properties (some deleted code just to be on point)
    31.  
    32. //adding to the model (some deleted code just to be on point)
    33.  
    34. //setting the counter
    35. pCounters.push_back(Counter(text2,0,true));
    36. ui->inputBox_2->clear();
    37. }
    38. /*---------------------------------------------------------*/
    39. //this is where it get called
    40.  
    41. void MainWindow::SaveFile()
    42. {
    43. QFile Save("streak Counter.txt");
    44. Save.open(QIODevice::WriteOnly|QIODevice::Text);
    45.  
    46. for(auto i = pCounters.begin();i != pCounters.end();i++)
    47. {
    48. QTextStream out(&Save);
    49. if(i->isVirigin())
    50. {
    51. out << i->getName() << ',' << "virigin" << ',' << i->getCreationDate() << endl; //getCreationDate() doesn't work!
    52.  
    53. }
    54. else
    55. {
    56. int counterNumber = i->getNumber();
    57. out << i->getName() << ',' << QString::number(counterNumber)<< ',' << i->getDate() << ',' << i->getCreationDate() <<"\n";
    58. }
    59. }
    60. Save.close();
    61. }
    To copy to clipboard, switch view to plain text mode 

    //output file (example)

    thing1,virigin,

    or

    thing2,3,22/2/2016,

    i hope that someone may pass by and help me... as no one did In StackOverflow.. and i really can't figure out whats the problem.

  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: Qt Function doesn't work And there is no error

    Have you looked at the value of CreationTime inside that function?
    Is it a valid QDate object?

    E.g.
    Qt Code:
    1. QString getCreationDate() const
    2. {
    3. qDebug() << Q_FUNC_INFO << CreationTime;
    4. return CreationTime.toString("dd/MM/yyyy"); //this one don't
    5. }
    To copy to clipboard, switch view to plain text mode 
    Or with the debugger.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    @anda_skoa

    well i never tried the qdebug before, however when i did what you said, CreationTime doesn't have anything in it ( "" ) .

    thats the QDebug message => class QString __cdecl Counter::getCreationDate(void) const QDate("")

    so i changed this

    Qt Code:
    1. pCounters.push_back(Counter(text2,0,true));
    To copy to clipboard, switch view to plain text mode 
    to

    Qt Code:
    1. pCounters.push_back(Counter(text2,0,true,QDate::currentDate())); //i thought this maybe the problem as Qt doesn't like my defaults
    To copy to clipboard, switch view to plain text mode 

    but still the variable don't get anything even though i explicitly passed the date to it.
    Last edited by eyad; 23rd February 2016 at 13:03. Reason: added the qdebug message

  4. #4
    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: Qt Function doesn't work And there is no error

    Since your member and your constructor argument have the same name, have you tried different names?

    Cheers,
    _

  5. #5
    Join Date
    Feb 2016
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Function doesn't work And there is no error

    i tried this after reading you reply.
    but it didn't change a thing.....

    i may give you the whole solution if you want , its a small program after all (2 headers , 1 cpp , 1 ui) 56kb total
    thats how desperate iam....

  6. #6
    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: Qt Function doesn't work And there is no error

    Attaching the program would definitely be useful.

    Cheers,
    _

Similar Threads

  1. Replies: 10
    Last Post: 3rd February 2015, 20:24
  2. Replies: 15
    Last Post: 23rd December 2013, 06:38
  3. Replies: 3
    Last Post: 1st May 2013, 20:44
  4. why on Linux ,doesn't work?
    By maider in forum Qt Programming
    Replies: 5
    Last Post: 11th March 2010, 08:57
  5. qSort doesn't work with member function
    By ber_44 in forum Qt Programming
    Replies: 10
    Last Post: 2nd June 2007, 12:00

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.