Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Loading a translation file causes my app to crash...
QtWS25 Last Chance

[solved] Loading a translation file causes my app to crash...

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hcwdjk
    wrote on last edited by
    #1

    The app is quite simple and there's no hackery involved. It loads the translation file in the standard way:
    @QTranslator translator;
    translator.load(QString("qtflux_") + QLocale::system().name());
    a.installTranslator(&translator);@

    Then, in a constructor of the main class I have a code which basically says this:
    @
    QAction *blah;
    (...)
    QFont df = qApp->font();
    df.setBold(1);
    blah->setFont(df);
    @

    This code crashes in setFont() If the translation file is loaded.

    No, blah in not 0.

    Any ideas would be very welcome.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      That code doesn't look bad. Can you provide the complete source code or a complete sample project?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jake007
        wrote on last edited by
        #3

        In provided code, QAction isn't inicialized.
        @QAction *blah = new QAction();@


        Code is poetry

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hcwdjk
          wrote on last edited by
          #4

          Thanks for answering. I uploaded it here: http://www.mediafire.com/?63s2qux18xs7h68

          It crashes if I load the qtflux_pl.qm translation. The crash is in line 29 of qtflux.cpp

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hcwdjk
            wrote on last edited by
            #5

            [quote author="Jake007" date="1330467930"]In provided code, QAction isn't inicialized.
            @QAction *blah = new QAction();@
            [/quote]

            I know it looks like that, that's why I said blah is not 0. I should have said it's initialized, as "not 0" not necesarily means it's valid ;) Let's say it's initialized inside the mysterious (...).

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hcwdjk
              wrote on last edited by
              #6

              Crap, I figured it out. Fuck I'm stupid. Thanks for the answers either way.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                What was the problem?

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  hcwdjk
                  wrote on last edited by
                  #8

                  I have this @QMap<QString, QAction*> actions;@

                  I initialized it like this:

                  @ QStringList an = QStringList()<<tr("Enable")<<tr("Settings")<<tr("About")<<tr("Quit");
                  foreach (QString s, an){
                  actions[s] = cmenu->addAction(s);
                  }@
                  And used like this:
                  @actions["Settings"]->setFont(df);@

                  That is, I initialized it with a translated string and later used it with original string.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    For using as the key into a hashtable I would advocate against translated strings. Use untranslated strings here. Do you have any reasons for using a map at all? If the number of actions is limited, why not use real member variables in your class?

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hcwdjk
                      wrote on last edited by
                      #10

                      bq. For using as the key into a hashtable I would advocate against translated strings.

                      Yeah, I know. I heaven't really thought this through... :P

                      bq. Do you have any reasons for using a map at all? If the number of actions is limited, why not use real member variables in your class?

                      The reason is that I spent 3 or 4 days once hunting down a bug caused by copy-pasting similar code 10 times instead doing it in a loop. That experience turned me into a vicious code duplication hunter ;)

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        In that cases I use a hybrid approach:

                        • distinct member variables (a QAction pointer) in case I need particular action
                        • a QList<QAction *> holding them all if I need to loop

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          hcwdjk
                          wrote on last edited by
                          #12

                          Yeah, you're probably right. Thanks again ;)

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved