Skip to content
  • 0 Votes
    5 Posts
    2k Views
    kshegunovK

    @the_

    will work

    Such a strong word ... it depends on the advisory locking mechanism used and most linux-es will support more than one. As duly noted in the documentation it's only guaranteed to work if the same scheme is used across all processes:

    Serialization is only guaranteed if all processes that access the shared resource use QLockFile, with the same file path.

  • 0 Votes
    9 Posts
    3k Views
    kshegunovK

    @dridk
    Hello,
    What I suggested is not compression per se, but a way to encode (meaning represent) base pair data more efficiently. As I noted, this is no way a complete solution, but I think it should give you a starting point. Since adenine is complementary to thymine the first could be encoded as a bit sequence 00 and the other as 11, while cytosine and guanine could be encoded as 01 and 10 respectively. This way you can get the complementary base by only inverting bits. Suppose you have encoded half the strain of DNA, then the complementary strain you get simply by inverting all the bits. Since the base data is only 2 bits fixed size you can use offsets to calculate where that data is exactly located in a long base pair sequence. Suppose you have a sequence of alleles and you know that some gene contains 3 alleles and starts with the 35th allele of the base-pair sequence, then you can access the gene sequence very easily. The gene should start at (35 - 1) * 3 = 102th base pair (or 102 * 2 = 204th bit) and the size is simply 9 base pairs or 18 bits. I just hope my biology is not failing me with the calculations. So if you had the whole sequence mapped in a binary file, to read up the gene you seek out the correct position directly by those offsets:

    QFile mySequenceFile("dnasequence.dna"); if (!file.open(QFile::ReadOnly)) ; //< You know the drill with handling errors file.seek(25); //< Go to the 25-th byte (200th bit) QByteArray geneSequenceData = file.read(3); //< Read 3 bytes (up to bit 224) // So in the byte array we've read we have the gene we're interested in, and it starts at the 4-th bit and ends at bit 22 // The total number of bits read is 24

    The whole point of having a structured binary file is to be able to seek around it without actually reading things. Obviously my example is pretty superficial and it's much better to have special class that represent a base pair sequence, class representing gene offsets and other data you might want to handle. Additionally, you probably'd need some meta-information written in that file (offsets of sequences, genes or other things) so you could locate what you need. This is not possible with text files, especially in a platform independent fashion. Moreover a sequence of 4 base pairs you encode in 4 bytes when you use text files, with the proposed encoding scheme you only need a single byte!

    Kind regards.

  • 0 Votes
    4 Posts
    2k Views
    J

    I was having this same problem, turns out I was restarting too soon. The file transfer was so slow that took over a minute to transfer a 2Mb file.

    I still don't have a good solution, I am using system("cp file1 file2") for Linux as a workaround, but don't have any suggestions for a portable solution.

  • 1 Votes
    3 Posts
    3k Views
    VRoninV

    Thank you very much

  • 0 Votes
    2 Posts
    909 Views
    JKSHJ

    Hi,

    Why not use QSettings?

    Anyway, if you want to implement this yourself, you first need to learn about file pointers and how to read and write to the same file at the same time:

    http://www.cplusplus.com/forum/beginner/66306/ http://stackoverflow.com/questions/17536570/reading-and-writing-to-the-same-file-using-the-same-fstream
  • 0 Votes
    6 Posts
    4k Views
    A

    Here is the code:

    QFile file("testfile"); if(file.open(QIODevice::ReadWrite | QIODevice::Text)) { QByteArray buf("Hello "); buf += file.readAll(); file.seek(0); file.write(buf); } else qDebug() << "error reading file";

    BUT it's not truncating the old content so the new content have to be bigger than the old one. If your second content could be smaller, just take the approach with a second file...
    Why don't you just append it to the end of the file?

    Cheers
    AlexRoot

  • 0 Votes
    10 Posts
    3k Views
    R

    Thank you very much for all the advice.
    If anyone encounters a similar issue, I managed to solve the issue in this manner.

    No changes to the '.pro' file.
    using this code to reference the file-path.

    QFile dayfile(QCoreApplication::applicationDirPath()+"/days.dat")

    again thank you for pointing me in the right direction!

  • 0 Votes
    2 Posts
    1k Views
    A

    @kybernetes You can use a 3rd party library to do this. I suggest taking a look at the guide on how to use id3lib with Qt. Basically it shows you how to add id3lib to your project.

  • 0 Votes
    2 Posts
    1k Views
    A

    why not try

    QFileSystemWatcher

    connect its signal to your model's slot.

  • 0 Votes
    4 Posts
    3k Views
    mrjjM

    @JonBriem
    Most welcome. If possible,please edit the first post you made and add [SOLVED] in front of title.

  • 0 Votes
    7 Posts
    2k Views
    C

    Sorry. Didn't notice my upload failed. It's fixed.

  • 0 Votes
    3 Posts
    23k Views
    KiwiJeffK

    You can open the file for writing and insert write QByteArrays to it via:
    QFile::write(const QByteArray & byteArray)

    Thus pick your favorite:
    QString::toUtf8() or QString::toLocal8bit().

  • 0 Votes
    16 Posts
    11k Views
    K

    @jjan
    Just for an iteration the code reads line by line. As long as the search text is found, it will provide the remainder of the line. There is real dependency to the content as long as it is displayble (probably also some non-displayable characters). There are some special characters marking the end of lines (line feed (LF) and carriage return (CR) are those at least).

  • 0 Votes
    4 Posts
    3k Views
    sneubertS

    Quick and dirty. Misses error checking and will produce nonsense if the file has more than one #QT_Read or #QT_End, or if the tokens are in the wrong order.

    void changeFile(const QString &fileNameAbsolutePath, const QString &textToInsert) { QFile originalFile(fileNameAbsolutePath); QFileInfo orgFlInfo(fileNameAbsolutePath); QFile tempFile(orgFlInfo.dir().absolutePath().append("/temp")); bool writeOriginalLine = true; originalFile.open(QIODevice::ReadOnly | QIODevice::Text); tempFile.open(QIODevice::WriteOnly | QIODevice::Text); if(originalFile.isOpen() && tempFile.isOpen()) { QTextStream org(&originalFile); QTextStream tmp(&tempFile); while(!org.atEnd()) { QString actualLine = org.readLine(); if(writeOriginalLine) tmp << actualLine << "\n"; if(actualLine == "#QT_Read") { writeOriginalLine = false; tmp << textToInsert << "\n"; } else if(actualLine == "#QT_End") { writeOriginalLine = true; tmp << actualLine << "\n"; } } originalFile.remove(); tempFile.rename(orgFlInfo.fileName()); } }
  • 0 Votes
    7 Posts
    4k Views
    WDR_937W

    @Wieland OK... So, you're replacing all the next lines in the string list to spaces and then splitting the strings by spaces. That's pretty neat. Thank you very much. This solution works perfectly for me. I upvoted all your answers. Thank you, Wieland.