Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.8k Posts
  • Pointers and opening a file from argument

    3
    0 Votes
    3 Posts
    2k Views
    H
    The StringList works now, I can confirm that. It seems like the error was in another class. (I sound like Toad saying: "The Princess is in another castle") However I've found that the error has happened in the parsing process... No string is appended to the QString. What an amusing thing to know. I found this out with the qDebug function. (This is a bit like when I script with Bash, only that it's a notch higher.) But I can figure that out by myself. :) I'm using the QXmlStreamReader in a somehow special way. It's used to fetch a file path which in turn will be used to make a QDomDocument. ;) I just wanted to keep the memory usage low, and to put them into QStrings right away is reasonable. I don't know if these work yet, because I haven't had any input for it. However, I have a hard time understanding a part of objects. When I define an object outside a class and then define something for that object inside a class, like a string, is that information preserved? And if it's not, how would I make a pointer to that information to be used in another class?
  • [SOLVED] QRegExp help needed

    5
    0 Votes
    5 Posts
    2k Views
    K
    thank you veeeee_d. i have also decided later after your first post that QString functions are the best for what i need to do. :). this topic is solved.
  • [SOLVED] Can't understand howto send HTTP GET request with authentication

    5
    0 Votes
    5 Posts
    9k Views
    R
    Solve it! I just need to replace my url string to: @request.setUrl(QUrl("http://login:password@myanimelist.net/api/anime/search.xml?q=bleach");@ More about it: http://doc.qt.nokia.com/4.7-snapshot/qurl.html#setAuthority
  • Layout centering on QStackedWidget

    5
    0 Votes
    5 Posts
    6k Views
    V
    I added a layout to the QBoxLayout, it looks like it works alright this way. Thanks for the help.
  • Delegate + Multi-Line Text

    2
    0 Votes
    2 Posts
    8k Views
    Q
    I sort of figured it out, but have some issues. 1)When rendered there are issues with the height of items (word-wrapped or not word-wrapped), the rectangle has padding at the top and bottom which I don't want 2)Selecting an item makes it vanish and doesn't provide normal highlighting behavior 3)Editing an item puts it back to a single line and doesn't provide word wrapping (which is fine, but I coded it to include word wrapping for presentational purposes and it's not working). I'm using a text layout to figure out word wrapping and I also want to provide the '...' truncating functionality b/c I don't want to allow extremely large entries of dozens of lines to be displayed, those I just defer to tool tips. Any help would be appreciated. wordwrapitemdelegate.h @ #ifndef WORDWRAPITEMDELEGATE_H #define WORDWRAPITEMDELEGATE_H #include <QStyledItemDelegate> #include <QWidget> #include <QtGui> #define LINE_LIMIT 5 /Truncate with ... after a certain amount of word wrapped lines/ class WordWrapItemDelegate : public QStyledItemDelegate { Q_OBJECT public: WordWrapItemDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {} void paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const; private: void details( QString text, QFont font, const QStyleOptionViewItem &option, int *lineCount, int *widthUsed ) const; }; #endif // WORDWRAPITEMDELEGATE_H @ wordwrapitemdelegate.cpp @ #include <QtGui> #include "wordwrapitemdelegate.h" void WordWrapItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { int widthUsed, lineCount; //Try and word wrap strings if(qVariantCanConvert<QString>(index.data())) { painter->save(); QPalette::ColorGroup group = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if (group == QPalette::Normal && !(option.state & QStyle::State_Active)) group = QPalette::Inactive; //set pen color depending on behavior painter->setFont( QApplication::font() ); if (option.state & QStyle::State_Selected) painter->setPen(option.palette.color(group, QPalette::HighlightedText)); else painter->setPen(option.palette.color(group, QPalette::Text)); //Text from item QString text = index.data(Qt::DisplayRole).toString(); //Begin word-wrapping effect (use the provided rectangles width to determine when to wrap) details(text, QApplication::font(), option, &lineCount, &widthUsed); //Word wrap the text, 'elide' it if it goes past a pre-determined maximum QString newText = painter->fontMetrics().elidedText(text, Qt::ElideRight, widthUsed); painter->drawText( option.rect, (Qt::TextWrapAnywhere|Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft), newText ); painter->restore(); } else { //Fall back on original QStyledItemDelegate::paint(painter, option, index); } } QSize WordWrapItemDelegate::sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const { int widthUsed, lineCount; //Try and word wrap strings if(qVariantCanConvert<QString>(index.data())) { //Update the size based on the number of lines (original size of a single line multiplied //by the number of lines) QString text = index.data(Qt::DisplayRole).toString(); details(text, QApplication::font(), option, &lineCount, &widthUsed); QSize size = QStyledItemDelegate::sizeHint(option, index); size.setHeight(lineCount * size.height()); return size; } else { //Fall back on original size hint of item return QStyledItemDelegate::sizeHint(option, index); } } void WordWrapItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const { int lineCount, widthUsed; //Fix editor's geometry and produce the word-wrapped effect for strings... if(qVariantCanConvert<QString>(index.data())) { //We need to expand our editor accordingly (not really necessary but looks nice) QString text = index.data(Qt::DisplayRole).toString(); details(text, QApplication::font(), option, &lineCount, &widthUsed); //Expand QSize extraSize = QSize(option.rect.width(), lineCount * option.rect.height()); QRect extraRect = option.rect; extraRect.setSize(extraSize); editor->setGeometry(option.rect); } else { //Fall back on original update QStyledItemDelegate::updateEditorGeometry(editor, option, index); } } void WordWrapItemDelegate::details( QString text, const QFont font, const QStyleOptionViewItem &option, int *lineCount, int *widthUsed ) const { //Use text layout to word-wrap and provide informmation about line counts and width's QTextLayout textLayout(text); *widthUsed = 0; *lineCount = 0; textLayout.setFont(font); textLayout.beginLayout(); while (*lineCount < LINE_LIMIT) { *lineCount = *lineCount + 1; QTextLine line = textLayout.createLine(); if (!line.isValid()) break; line.setLineWidth(option.rect.width()); *widthUsed = (*widthUsed + line.naturalTextWidth()); } textLayout.endLayout(); *widthUsed = (*widthUsed + option.rect.width()); } @
  • [Solved] simple template class is not compiled

    3
    0 Votes
    3 Posts
    2k Views
    G
    I will read it. Thank you very much for fast answer and very useful link!
  • Security and the well constructed Qt plugin

    5
    0 Votes
    5 Posts
    2k Views
    J
    Thanks for helping.
  • Multiple inheritance from QObject (QObject is an ambiguous base of ...)

    12
    0 Votes
    12 Posts
    36k Views
    A
    [quote]What is the charm pattern?[/quote] Perhaps that indeeds needs a bit of explanation. In the past, there have been examples of classes that added certain behaviour to a widget. A good example is the "FlickCharm":http://labs.qt.nokia.com/2008/11/15/flick-list-or-kinetic-scrolling/ that demonstrates adding kinetic scrolling to scroll area's. The pattern shown there can be applied much more broadly. There are many other things you can achieve in much the same way. The basic idea is that you create a class, typically a QObject-derived class, that "magically" adds functionality to another object. That is: not through subclassing, but by instantiating a new object that manipulates how the widget looks or works. You can use things like event filters to make them work. I write them in a way that they manage their own life time, by making themselves children of the object they are supposed to act on. Futhermore, I usually make the constructor private, and create a static method like this: @static MyCharm* MyCharm::cast(QWidget* subject) ; @ that you use to create the charm. That allows tricks like making sure that there is only one instance of the charm in question for a single subject widget. Working this way is quite a powerful programming pattern. It allows you to change the behavior in lots of little but very useful ways, without subclassing. The charm can often apply to multiple types of widgets, and it prevents an explosion of derived types. Examples of charms I have written, are: A charm to enable verifying of the contents of tabs before allowing a tab change in QTabBar or QTabWidget A charm to make it possible to rename tabs of QTabBar or QTabWidget A charm to add small inline command buttons inside or outside a QLineEdit or a QComboBox. You can cast this charm multiple times to add multiple buttons. A charm to make the selection list of a QComboBox wrap around. For this way of programming, Qt offers some very powerful tools to make this possible, especially the event filter. I call this the charm pattern.
  • No such slot error

    5
    0 Votes
    5 Posts
    3k Views
    J
    Damned. Thanks for lighting my mind. What a stupid mistake... But I still get the error message.
  • Convert IplImage to QByteArray

    7
    0 Votes
    7 Posts
    7k Views
    S
    bq. 1 QByteArray(image->imageData); is likely to truncate your data, as it stops at the first null byte. change it to Yes, i noticed about that. forgot to correct above code :) bq. An UDP datagram can only contain 8192 bytes, but you discovered that already in that other thread. Although with TCP I have no chance to send 30 fps video by individual images on LAN Ethernet cable... I found that sending Images is not a good idea. It should be an AVI stream with compression. Thanks
  • How to make a project that is done with QtQuick to a gui application?

    5
    0 Votes
    5 Posts
    2k Views
    T
    Take a look at "QxtLineEdit":https://bitbucket.org/libqxt/libqxt/src/tip/src/gui/qxtlineedit.h, which has reset button in its 'tip' version. Actually, I haven't tested it yet.
  • 0 Votes
    13 Posts
    9k Views
    L
    Sorry for late answer, i didn't have my laptop. Thanks a lot Andre and Volker! It works :) [quote author="Andre" date="1322549362"] [quote author="Leon" date="1322521126"] What should i do so as the items that doesn't match be removed and restored like i said? somethink like setFilter(ui->lineedit->text)[/quote] Yes, something like that. You could make a slot like this: @ void updateListFilter(const QString& filterString) { proxyModel->setFilterWildcard(QString("%1").arg(filterString); } @ and then somewhere call @ connect (ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateListFilter(QString))); @ [/quote]
  • 0 Votes
    7 Posts
    3k Views
    F
    By the way, if you will hit some limit (maybe an embedded device) you can store in a ini file names or paths to reach and load other specific ini files. But as stated in this thread, you will never hit the ini file size unles you use it in an improper way (e.g., storing large strings as user data).
  • [Solved] Not all the text in my application is translated.

    14
    0 Votes
    14 Posts
    7k Views
    S
    I get the same problem but I can't find the solution ? please tell me how you resolved it ? the ts file doesn't generated absolutely @ Project MESSAGE: C:/Qt/4.7.4/mkspecs/features/default_post.prf(5):Function 'system' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(66):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(69):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(72):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(75):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(78):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(80):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(82):Function 'eval' is not implemented C:/Qt/4.7.4/mkspecs/features/debug_and_release.prf(84):Function 'eval' is not implemented This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. @
  • Send large data via UDP / Split QByteArry by size?

    6
    0 Votes
    6 Posts
    10k Views
    A
    Actually, in principle UDP is much more suitable for this application. You don't want to halt a whole video stream just because you missed a single frame. However, it does take some work to get it to work... On a sidenote: it looks like you want to send an uncompressed stream of images. If we add network overhead to your image size, you are trying to send about 1MB per frame. To make that into streaming video, you end up with about 24MB/s raw network speed. I hope you realize you need a Gbit network to get that throughput? 100Mbit is not enough for such a data rate.
  • [closed] ItemDelegates,TreeView,And Multi-Line Text

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    EddyE
    Duplicate from "this thread":http://developer.qt.nokia.com/forums/viewthread/12167/. I'm closing it.
  • QDir delete all files function?

    20
    0 Votes
    20 Posts
    22k Views
    sierdzioS
    Nice, thanks!
  • ItemDelegates,TreeView,And Multi-Line Text

    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • Can't make Connection Correctly in Qt Designer

    11
    0 Votes
    11 Posts
    4k Views
    A
    Thanks! I got it to work! I knew there was something that wasn't right. I'll remember that checkable problem.