Results 1 to 13 of 13

Thread: QDateTime application level format string

  1. #1
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default QDateTime application level format string

    I am trying to change default datetime format for my entire application. What i was expecting is QDateTime static method that sets default string format. With no luck of course.
    I also tried QLocale::setDefault, but there i am only able to choose country/language. (or i am missing something). Code refactoring and replacing QDateTime to string functions doesnt seam like a good idea.
    What is the proper way to set custom global datetime format for application?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QDateTime application level format string

    Quote Originally Posted by davidovv View Post
    What is the proper way to set custom global datetime format for application?
    Write and use a function that does that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QDateTime application level format string

    Quote Originally Posted by wysota View Post
    Write and use a function that does that.
    wysota, that is a teasing comment

    Is there a single place where i can set datetime format string so that it afects every QDateTime::toString() function, not only for datetime objects that i create in code, but also for datetime widgets (like QDateTimeEdit and model based views that display datetime fields from database)
    Qlocale seamed like the place, but there i could set default language and country, not the custom format.

    If there is no such place, how do fellow programmers usualy "write" function that does that.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QDateTime application level format string

    Quote Originally Posted by davidovv View Post
    If there is no such place, how do fellow programmers usualy "write" function that does that.
    They don't because fellow programmers don't feel a need for such functions. If fellow programmers want to change default behavior of something, they reimplement virtual methods of objects using them, e.g. they implement custom delegates for views if they want to show custom content in them. If fellow programmers want to shoot themselves into their feet, they take a gun and pull the trigger.

    And seriously if you try to change the default format of the date output, you break all the functionality already in Qt depending on that format being exactly how it is now.
    Last edited by wysota; 10th March 2013 at 00:08.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QDateTime application level format string

    wysota, now you criticize your own comment,
    first you say "write fucntion that does that"
    and after "fellow programmers don't feel a need for such functions"

    anyway, What i am trying right now is to reimplement QLocale::dateFormat and QLocale::dateTimeFormat and to call QLocale::setDefault(myLocale)
    since those are not virtual methods and i am getting strange compilation errors as soon as i include derived class files, is this what i am doing even possible?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QDateTime application level format string

    Quote Originally Posted by davidovv View Post
    wysota, now you criticize your own comment,
    No, I don't.

    first you say "write fucntion that does that"
    and after "fellow programmers don't feel a need for such functions"
    Yes. We don't need that. If you want it, implement it yourself. If you don't want to implement it yourself because you'd want it to be already implemented for you then wait until someone else does it which is very doubtful because of my second sentence of this paragraph.

    anyway, What i am trying right now is to reimplement QLocale::dateFormat and QLocale::dateTimeFormat and to call QLocale::setDefault(myLocale)
    Bad idea since non of these are virtual. And I really have no idea why you'd want that in the first place.

    is this what i am doing even possible?
    I have no idea what you are trying to do. I mean I know you're trying to make something default not default but why you are doing that is a riddle to me.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QDateTime application level format string

    Quote Originally Posted by wysota View Post
    No, I don't.
    Yes you do, you say write function and then We don't need that

    If fellow programmers want to shoot themselves into their feet, they take a gun and pull the trigger.
    What is the point of this edit??

    And I really have no idea why you'd want that in the first place.
    I want to set datetime format once, in one place, so that every form, widget, edit... that displays datetime uses that format, I dont want to go to every file in the project and search for datetime usage and change functions, i dont want to go to every model based view i created long time ago, and implement custom datetime delegate. QLocale "almost" does what i need, i create
    Qt Code:
    1. int main(int argc, char *argv[]){
    2. QLocale locale(QLocale::Polish, QLocale::Poland);
    3. QLocale::setDefault(locale);
    4. ...
    To copy to clipboard, switch view to plain text mode 
    and it afects every datetime view, but my country format is wrong, and even if it was correct, i would like to tune it.

    If you can't or won't help, please dont comment at all

    Write and use a function that does that.
    comment like this isn't helpfull.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,534
    Thanks
    13
    Thanked 1,576 Times in 1,505 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDateTime application level format string

    No amount of to-and-fro will make a function that does not exist suddenly spring into existence. If you want a date format that differs from the locale implied one then you need to code for it. There's no mechanism that can intercept all argument-free calls to QDateTime::toString() and QLocale equivalent. Even if there were, the default item delegate for item views formats the date explicitly in QLocale::ShortFormat so you would still have to replace the delegates relying on default format.

    If you think such an ability is globally important then by all means code it, submit for inclusion in Qt, and fight for it. Since you will be proposing breaking compatibility with all existing Qt code you will need to wait a while to get it in.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QDateTime application level format string

    Quote Originally Posted by davidovv View Post
    Yes you do, you say write function and then We don't need that
    Yes. I don't need that, Chris doesn't need that. Thus we won't write that function. If you need that then by all means write such a function, rebuild Qt and be happy in your life.

    What is the point of this edit??
    The point is to show you that you are trying to shoot yourself in your foot by trying to break something that works. I understand that you want some behaviour that is not default, but trying to make it default is not a good solution. I'm sorry that you have to go through your code and reimplement 10, 20, 100 or 1000 views to set a new delegate for them (if you know how to use search and replace, you can do that in 10 seconds for all your views). If you have thought about it upfront when you were coding your views or whatever you have there, you would have saved yourself time now. Since you haven't then you have to do that additional work. You can take a shortcut and just change Qt in a couple of places specifically for your program but I strongly doubt it will not backfire on you sooner or later.

    So again, if you want a function that will convert a date to a custom string format, write such a function and use it wherever it needs to be used. Just like I wrote in my first reply in this thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QDateTime application level format string

    If i was doing everything right, i wouldn't be here. Also, i am not lazy, and if proper way is to reimplement my views, i will do it. I allready spent more time on this thread than it would take me to refactor my code. First I wanted to check here if anyone knows a better, more centralised way to do it. When i was coding my views i did think upfront, and used default toString() behavieour (even if default didn't satisfy me), thinking that i could change this default behaviour with qlocale for example.

    Pardon me if i still think that if there should be a way to set global default behaviour manualy, not just by choosing country and language, or implementing custom delegates on every view.

    and another thing, you constantly repeat "we dont need that", i supose you dont go from thread to thread and if someone neads something you brag that "you dont need that"
    Maybe something like "it is a bad idea because of...." or "you should do this instead..." would be more appropriate

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QDateTime application level format string

    Quote Originally Posted by davidovv View Post
    Pardon me if i still think that if there should be a way to set global default behaviour manualy, not just by choosing country and language, or implementing custom delegates on every view.
    A public function (any public function) that is part of a library (any library) can be called by any code -- your code or code of the library itself. If you set a "global" behaviour then you influence not only your code but also code of the library itself that can depend on receiving this and not other result from a function it knows to work in a particular way. For instance, there might be a function somewhere that extracts the textual description of something using the string and you globally change the format of the string, that code will simply fail and you'll be spending hours and hours trying to find the problem or complaining that the library is buggy because "it used to work yesterday and now it doesn't".

    and another thing, you constantly repeat "we dont need that", i supose you dont go from thread to thread and if someone neads something you brag that "you dont need that"
    My response was a direct response to your statement about fellow programmers. Fellow programmers don't (let me quote your post) "usualy »write« function that does that" because fellow programmers don't need a function that does that. If you want to abuse a function then go ahead -- do it at your own responsibility but don't expect that there is (or should be) a built-in way to do that.

    Read my posts again and think whether they are "bragging" anything or merely answering questions you ask. If you ask wrong questions, don't expect to receive answers to right questions.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QDateTime application level format string

    Fellow programmers don't (let me quote your post) "usualy »write« function that does that"
    so you quote my post, where i quoted and repeted your words from first post, and reproach me for wanting something you sugested??

    Read my posts again
    you edited your post after my reply, my reply was to you original post, if the post was complete maybe i wouldnt ask no more questions. Since that moment this thread had more of quoting quotes, than talking about specific problem

    to summarize, i was simply asking how do you customize datetime in my application, asked if it is good idea to tune QLocale, and you answer is there is no easy way that wouldn't create other problems, and that i have to implement custom delegates, and refactor my code.

    Dont get me wrong, you are helpful and you helped few times in the past and now, but you are dificult man to talk to.


    Added after 4 minutes:


    and another thing, there is a proverb

    There are no wrong questions, only unasked ones
    Last edited by davidovv; 10th March 2013 at 15:34.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QDateTime application level format string

    Quote Originally Posted by davidovv View Post

    Added after 4 minutes:


    and another thing, there is a proverb

    There are no wrong questions, only unasked ones
    Look, this is really simple -- If you ask a wrong question, we can either bluntly say it's wrong and try to determine what is the real question you should have asked or we can simply ignore your wrong question. I usually tend to do the first because I have an impression that this lets us still solve the real problem (despite maybe worsened mood of the person asking) in contrast to just ignoring your question which lets me save my mood and time (and what the netiquette suggests anyway) but makes you stay in exactly the same spot you have been prior to asking that question.

    In other words, if you ask a wrong question, it can very likely remain without an answer, paraphrasing your proverb to "there are no wrong questions, only unanswered ones".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Getting problems to convert from string to QDateTime
    By cesroc in forum Qt Programming
    Replies: 6
    Last Post: 2nd April 2012, 11:37
  2. Replies: 5
    Last Post: 10th May 2011, 20:38
  3. Replies: 3
    Last Post: 27th July 2008, 16:39
  4. how to format a number into a const width string ?
    By lovelypp in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 21:45
  5. Replies: 1
    Last Post: 30th June 2006, 05: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.