Results 1 to 17 of 17

Thread: simple questions. qt3 to qt4

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default simple questions. qt3 to qt4

    Hi. I am having a great deal of trouble with some of the documentation in Qt4. I have spent a lot of time on just these 2 VERY BASIC items

    Qt3: text = listBox ->text ( index ); and/or item index from QListBox. how in QListView or QListWidget or ???

    Qt3: textEdit-> undo & textEdit->redo
    in Qt4 I can find out if they are enabled, but not how to use them.

    I would appreciate some help
    thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple questions. qt3 to qt4

    Qt3: text = listBox ->text ( index ); and/or item index from QListBox. how in QListView or QListWidget or ???
    QListWidget

    item(row)->text()

    in Qt4 I can find out if they are enabled, but not how to use them.
    Look at editing key bindings in QTextEdit class Reference.

  3. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    Quote Originally Posted by munna
    QListWidget

    item(row)->text()



    Look at editing key bindings in QTextEdit class Reference.
    Thanks, but, if I understand your suggestion corectly, key bindings are not what I'm looking for.
    I am writing a program, not using one.
    my question is "How do I put, in my program, the functionality of textedit's "undo" & "redo" present in Qt3?

  4. #4
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    I have solved my list box problem by using QListWidget, but the "undo" and "redo" remain.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: simple questions. qt3 to qt4

    Quote Originally Posted by impeteperry
    "undo" and "redo" remain
    This should make your life easier..
    Qt Code:
    1. textEdit->setUndoRedoEnabled(true);
    2. actionUndo->setEnabled(false);
    3. actionRedo->setEnabled(false);
    4. connect(actionUndo, SIGNAL(triggered()), textEdit->document(), SLOT(undo()));
    5. connect(actionRedo, SIGNAL(triggered()), textEdit->document(), SLOT(redo()));
    6. connect(textEdit, SIGNAL(undoAvailable(bool)), actionUndo, SLOT(setEnabled(bool)));
    7. connect(textEdit, SIGNAL(redoAvailable(bool)), actionRedo, SLOT(setEnabled(bool)));
    To copy to clipboard, switch view to plain text mode 
    See also Editing key bindings.

  6. #6
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    Thanks, What it looks like is that they have dropped the "undo" & "redo" functions entirely in Qt4, and what you suggest is a "work around". I can do that, but I'm not happy.

    Thanks for your help. I really needed that.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: simple questions. qt3 to qt4

    Quote Originally Posted by impeteperry
    What it looks like is that they have dropped the "undo" & "redo" functions entirely in Qt4, and what you suggest is a "work around". I can do that, but I'm not happy.
    It's not a "workaround". The new QTextEdit (and QTextBrowser) is based on the underlying document. QTextDocument is a new class in Qt 4 and represents the structure of a rich text document. The document is now responsible for undo/redo functionality. What are you not happy with? Too complicated?

  8. #8
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    Your comment is funny and kind of hits the mark.
    In all the programming I have done since the '70s (self taught) that which I didn't understand seemed complicated.
    For some reason this switch from Qt3 to Qt4 has been dificult for me.
    Looking at the QTextEdit documentation, I did not see a reference to QTextDocument, so I did not find the "undo" function which I knew had to be somewhere. I did a search for "undo" on the whole QTextEdit class document, came up with the "isUndoEnabled"s but no plain "undo."

    Thanks to you, I'm now happy.

  9. #9
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    i should say "almost" happy.
    Thanks to your help and the "textEdit" demo, I now have a QTextEdit where I can edit, undo & redo BUT I need to convert the QTextStream to a QString. i see that there is a "QTextStream::readAll ();" member to do that, But I am having trouble codeing it.
    Among many uses,i have a large number of small strings (people's addreses" which I keep in a "StringList" for easy handling.

    Some more help would be appreciated.

    PS. What I don't understand; I use a "QTextEdit" widget to edit some text.
    "now is the tim for all good men\nto come to the aid.....", I miss-spelled "time" so I go to the widget that is designed to "edit text", or so it's name implies, and add the "e" to "tim". And I should now have a "now is the time for all good men\nto come to the aid....." bit of text, but no, I now have a QTextStream what ever that is. There is enough functionality in QString for me to implement my own "undo/redo" and most of the other stuff that they have put in "TextEdit" as shown in the demo. It looks like "Microsolt" wrote it to me.
    There, now if I could get my text out of "textEdit" I would really be happy.

    Please excuse the blow off.
    Last edited by impeteperry; 2nd April 2006 at 21:03.

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: simple questions. qt3 to qt4

    I find << and >> operators convenient.
    You don't "convert" a stream to a string, you read from a stream to a string.

    Following example demonstrates usage of QTextStream and QStringList:
    Qt Code:
    1. QString string1("string 1");
    2. QString string2("string 2");
    3.  
    4. QString data;
    5. QTextStream textStream(&data);
    6.  
    7. // writing strings to a stream
    8. textStream << string1 << " " << string2;
    9.  
    10. // stream's internal data
    11. qDebug() << data; // outputs "string 1 string 2"
    12.  
    13. // reading from a stream to a string list
    14. QStringList wordList;
    15. while (!textStream.atEnd())
    16. {
    17. QString word;
    18. textStream >> word;
    19. wordList << word;
    20. }
    21.  
    22. qDebug() << wordList; // outputs ("string", "1", "string", "2")
    23.  
    24. // writing a string list to a stream
    25. foreach (QString word, wordList)
    26. textStream << word;
    27.  
    28. qDebug() << textStream.readAll(); // outputs "string1string2"
    To copy to clipboard, switch view to plain text mode 

    Hope you find it useful! And if not, please give a bit more comprehensive explanation of what you are trying to do..
    J-P Nurmi

  11. The following user says thank you to jpn for this useful post:

    impeteperry (3rd April 2006)

  12. #11
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    while I'm digesting your reply. let me give youa run down on what I'n doing.

    1. I am an engineer and am writing programs for specific applications for non-computer savy users.
    2. I do not use "pop-up" or "tool bars" in the usual sense.
    3. I use a "control" string for program control.
    " a,b,c,d,e,f, etc." where each position will have progam information. For example "e" might be "123-4x16" representing the location of column "d" on level "b" etc. With this system any module or function knows what it is dealing with by accessing this control string.
    4 I use a "functionNumber" for program flow.
    5 I have a "masterList" QStringList where each element in the list is itself a QStringList which can be split into ies own string list, names of buttons, prompts etc. each element in these sub-lists are keyed to the functionNumber.
    It is this masterlist I need to be able to edit. I Join the elements into one long string and put it in a "textEdit" widget for editing.
    6. Program operation is totally language ( and/or spelling ) independent. With the "signal-slot" system, programming is a breeze.
    7. I have a row of Pushbuttons accross the bottom of the screen and a row of labels obove them representing the keyboard function keys for implementing a given function. The labels on the pushbuttons name the function. The names come from the appropiate sub-list of the master list mentioned above.
    8. The user has his/her choice of pushing a function key, entering an accelerator key (given in the label on the push button) ,clicking on a pushbutton with the mouse or dbl clicking on an option when there is one.

    The key to the whole system is the masterList. I have a single textEdit Wiget with the MasterList broken down in to a single string text. Qt3 was great for this.

    If I know how to attach a snapshot I would or if you send me an e-mail at "impeteperry@cox.net" I can send you some.
    Last edited by impeteperry; 3rd April 2006 at 02:23.

  13. #12
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    Thanks, please forget all that has gone before, QTextStreams, QTextEdit widgets, Undos, redos, my rantings and ravings etc.

    All I need is the code to put in my program for a user to be able to change the word "sunny" to "raining" in the QString k. "It is sunny today".

    In Qt3 where "myTextEdit" is an instance of the QTextEdit widget.
    "myTextEdit->setText( k );"
    "k = myTextEdit->text();".

    Please, what is the code to do that in Qt4? (Text in, text out.)

  14. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: simple questions. qt3 to qt4

    Quote Originally Posted by impeteperry
    All I need is the code to put in my program for a user to be able to change the word "sunny" to "raining" in the QString k. "It is sunny today".
    QString::replace()
    J-P Nurmi

  15. The following user says thank you to jpn for this useful post:

    impeteperry (3rd April 2006)

  16. #14
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    I feel like an idiot. What I have been looking for from the beginning is:

    QString QTextEdit::toPlainText () const

    This line of code solves all my problems. I don't know how I missed it.
    I thank you for your efforts, they are very much appreciated.

    pete perry.

  17. #15
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: simple questions. qt3 to qt4

    Ahh, I didn't realize that the issue was about retrieving the contents of the text edit..
    J-P Nurmi

  18. #16
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple questions. qt3 to qt4

    Quote Originally Posted by jpn
    Ahh, I didn't realize that the issue was about retrieving the contents of the text edit..
    Ain't communication fun!

    I'm going to the Linux World conference in Boston tomorrow. Do you ever get to the US?. I've been to Denmark & Sweden, but not Finland. Again Thanks.

  19. #17
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: simple questions. qt3 to qt4

    Quote Originally Posted by impeteperry
    Ain't communication fun!

    I'm going to the Linux World conference in Boston tomorrow. Do you ever get to the US?. I've been to Denmark & Sweden, but not Finland. Again Thanks.
    Not that I have plans or anything, but who knows, maybe some day.. No problem at all.
    J-P Nurmi

Similar Threads

  1. very simple and basic FAM/Gamin wrapper for qt
    By momesana in forum Qt-based Software
    Replies: 0
    Last Post: 8th April 2008, 12:46
  2. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12
  3. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  4. [QT4] Trivial question(s)
    By agent007se in forum Newbie
    Replies: 1
    Last Post: 27th June 2006, 14:59
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.