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. Sideconditions in QDir-constructor?
Forum Updated to NodeBB v4.3 + New Features

Sideconditions in QDir-constructor?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    justMe
    wrote on last edited by
    #1

    Hello everyone!

    I have written the following function:

    (I´ve got a file with an URL in each line. I want to get the URL given in the oid-th line. For my current problem, just the first 5 lines are important.)
    @
    QUrl MyClass::getUrl(int oid) {
    QString tmp = MyConstants::filelocation();
    qdebug() << "1" << tmp;
    QDir tmpDir(tmp); //here, it crashes
    qdebug() << "2";
    QFile* f = new QFile(tmpDir.absoluteFilePath("Objects2.dat"));
    QString resultByteArray;
    if (f->exists()) {
    f->open(QIODevice::ReadOnly); //TODO: catch false
    for (int i = 0; i < oid; i++) {
    if (f->atEnd()) {
    qwarning() << tmpDir.absoluteFilePath("objects.dat") << " has less than " << oid << " entries.";
    return QUrl(".");
    }
    f->readLine();
    }
    resultByteArray = f->readLine();
    resultByteArray.remove(QRegExp("\r"));
    resultByteArray.remove(QRegExp("\n"));
    f->close();
    } else {
    qwarning() << "Failed to open " << tmpDir.absoluteFilePath("Objects2.dat") << ".";
    }
    delete f;
    QString result = resultByteArray;
    return QUrl(result);
    }
    @
    I call this function twice in my program. In one case, it always works and in a second, it always crashes, when I call the constructor of QDir.
    Are there any sideconditions, which must be fullfilled, so that I can call the constructor successfully?
    By the way: tmp (my filelocation) is the same in both situations...

    Thanks a lot,

    Maria.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      There are no special conditions to be fulfilled. You might be experiencing a memory corruption or something like that. These can pop up their ugly heads at seemingly totally unrelated pieces of code. Try using valgrind or something like that to check for these.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Afaik, QDir has no sideconditions.

        Can you check, what the debugger gives you as call stack and where exactly it crashes?
        also, what content the variables have exactly

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          justMe
          wrote on last edited by
          #4

          Thanks to both of you for your fast replies!

          Though I don´t like your answers (just kidding :D).

          As I´m working on Windows (and using Netbeans, which somehow does not really help me debugging), I´ll install a virtual machine to examine my code properly.

          I´ll report, when I´ve got some new findings (or questions).

          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