Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: Basic Qt4 tutorial needed

  1. #1
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Basic Qt4 tutorial needed

    Something that I would love to see would be a tutorial showing how to make a basic dialog ( .ui) and use it like the majority of us will probably program.

    In other words, I think it would be really helpful to myself and many others who wish to start learning Qt4 (not Qt3) with a tutorial using the latest Kdevelop (3.3.x) with the embedded Qt4 Designer. Or even just a dialog with the designer and then how to include it and use it in the source and make a custom slot.

    Like if someone could provide details on how to create this:
    http://doc.trolltech.com/4.1/tutorial-t5.html
    by creating the dialog in Kdevelop's embedded Qt4 Designer and show how to make a custom slot and use the *.ui file, I think that would greatly help many of us out.

    Simply providing the finished source files isn't very helpful. The step that I think most of us are stuck on is getting from the dialog created in the designer ( .ui) to how to use it code wise.

    Any kind souls out there?
    Paul

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed


  3. #3
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic Qt4 tutorial needed

    Thanks for the links, however I've been through each one of those links already before posting and still couldn't put the whole picture together for creating a simple dialog with them.

    The first link is the most helpful, but isn't quite what I'm looking for. And the last 3 either don't deal with Qt4, or don't have any tutorials at all (link 2).

    I'm still trying to figure out how to get my simple dialog working, I've been referencing this link mainly, but still no luck.
    http://doc.trolltech.com/4.1/designe...component.html
    Sure it talks about sub classing the dialog, but the dialog they build leading up to that point isn't straight forward. They jump around way too much.

    I can build a dialog with Qt4 designer, but can't figure out how to make use of it. I can hop in Kdevelop ( I agree Kdevelop doesn't have Qt4 designer integrated!) and then can create a new project (c++ -> QMake project -> Hello world). Then under the project settings, select Qt4 and give it the path to the header files and such (/usr/include/qt4). Then in the automake manager I can add a main.cpp and the created dialog. But now what? Subclass the .UI file? Thats where I get the most lost.

    Paul

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed

    [QUOTE=pthomas]Thanks for the links, however I've been through each one of those links already before posting and still couldn't put the whole picture together for creating a simple dialog with them.[quote]


    The first link is the most helpful, but isn't quite what I'm looking for.
    What are you loking for then?

    And the last 3 either don't deal with Qt4,
    Do they have to deal with Qt4? The overall mechanism is identical both in Qt3 and Qt4. Only minor things changed when it comes to the technique of writing applications and they are covered (those changes) either by that video tutorial from Trolltech or one of Johan's articles at digitalfanatics. If you want a huge tutorial about eveything, you won't find it.

    or don't have any tutorials at all (link 2).
    They do, you didn't look well enough (although they may not necessary be walk-by-hand tutorials).

    I'm still trying to figure out how to get my simple dialog working, I've been referencing this link mainly, but still no luck.
    What is wrong with your dialog? I stress it once again, that you CAN'T use KDevelop's embedded Designer component to create Qt4 widgets, I think that's your problem -- you don't have any Qt4 features of Designer.

    http://doc.trolltech.com/4.1/designe...component.html
    Sure it talks about sub classing the dialog, but the dialog they build leading up to that point isn't straight forward. They jump around way too much.
    Could you explain? I don't see them jumping around, just presenting choices one has -- that page is especialy usefull for people transfering from Qt3.

    I can build a dialog with Qt4 designer, but can't figure out how to make use of it. I can hop in Kdevelop ( I agree Kdevelop doesn't have Qt4 designer integrated!) and then can create a new project (c++ -> QMake project -> Hello world). Then under the project settings, select Qt4 and give it the path to the header files and such (/usr/include/qt4). Then in the automake manager I can add a main.cpp and the created dialog. But now what? Subclass the .UI file? Thats where I get the most lost.
    You can't use KDevelop to manage Qt4 project, please remember that. You have to do it by changing the .pro file directly and making sure KDevelop doesn't mess it up. And answering your last question -- that's where the tutorial page you mentioned comes in -- you have there different choices you can take at that moment. One way or the other, you have to create a class derived from one of Qt widget classes and apply that UI there. It is explained in the tutorial how to do it.

  5. #5
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by wysota
    Quote Originally Posted by pthomas
    Thanks for the links, however I've been through each one of those links already before posting and still couldn't put the whole picture together for creating a simple dialog with them.
    What are you loking for then?
    Oh man. I'm not sure, but I'll know if I find it! I kind of did last night while I was still searching around and experimenting with stuff... Qt enlightenment

    Quote Originally Posted by wysota
    They do, you didn't look well enough (although they may not necessary be walk-by-hand tutorials).
    - Yup, I agree.

    Quote Originally Posted by wysota
    What is wrong with your dialog? I stress it once again, that you CAN'T use KDevelop's embedded Designer component to create Qt4 widgets, I think that's your problem -- you don't have any Qt4 features of Designer.
    I think I was still suffering from lack of understanding. I did actually get it working late last night. It was more of me not understanding how to use the .ui files after creating them with the designer. I'm going to give another one a try tonight. That was part of my problem originally too I think, using the designer in Kdevelop. I stopped using it shortly after opening this post.

    Quote Originally Posted by wysota
    Could you explain? I don't see them jumping around, just presenting choices one has -- that page is especialy usefull for people transfering from Qt3.
    I wrote that badly, I meant the pages leading up to that link. Like if you click on that link and then jump back a few pages to where they first begin the dialog creation. I was trying to use it more like a how-to, but its more for reference.

    Quote Originally Posted by wysota
    You can't use KDevelop to manage Qt4 project, please remember that. You have to do it by changing the .pro file directly and making sure KDevelop doesn't mess it up. And answering your last question -- that's where the tutorial page you mentioned comes in -- you have there different choices you can take at that moment. One way or the other, you have to create a class derived from one of Qt widget classes and apply that UI there. It is explained in the tutorial how to do it.
    Actually starting with version 3.3.x you can. They even stated Qt4 support on their features page for this release. And from my experience last night, it works quite well provided you setup the project right and then only use the Automake manager for adding/removing files.

    Thanks for the help,
    Paul

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by pthomas
    Actually starting with version 3.3.x you can.
    Actually you can't. At least not in my definition of the word "manage". I mean a Qt project not a KDE one. Qt projects are managed by QMake, not by automake and KDevelop's QMake project manager doesn't support Qt4 at all. I'd even say in anti-supports it, as it breaks Qt4 project files and you can't do anything about it. You can't even compile a project using Qt4 out of the box. The only thing that works there is providing proper include names while defining superclasses to a class. I know KDevelop is a KDE project and KDE people use automake instead of QMake, but in my opinion "support" is not about using one of the undocumented options to make something work but to work by default (it's not documented anywhere that this "support" concerns only automake based projects).

  7. #7
    Join Date
    Jan 2006
    Location
    Cincinnati, Ohio, USA
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Basic Qt4 tutorial needed

    What type of IDE or what programs do you use for your Qt development stuff? It seems like the best way so far might just be a combination of the Qt Designer for dialogs and main windows + Kate for code editing.

    Is there another good combination/IDE that you would recommend?
    Paul

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed

    Qt Designer+Qt Assistant+Qt Linguist+Kdevelop

  9. #9
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    to pthomas:
    Here you can find a good explanation of changes in .ui files.

    For coding you can still using KDevelop and manage .pro files by hand or by qmake if you rather prefer.
    About subclassing ui, you can run uic by hand on the .ui file like:
    Qt Code:
    1. uic somefile.ui >somefile.h
    To copy to clipboard, switch view to plain text mode 
    and then use the header generated file as a normal file with a parent class definition.

    Hope it helps.
    Kandalf
    There's no place like ~

  10. #10
    Join Date
    Jan 2006
    Location
    Athens-Greece
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    I use KDevelop in linux and Code::blocks under windows.

    You can find my first Qt4 successfull attempt in creating a simple dialog with designer and add two buttons and custom slots.

    http://www.qtcentre.org/forum/showpo...4&postcount=27

    Hope this helps
    If there weren't noobs there would be no experts

  11. #11
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    i found this imho very good book:
    http://cartan.cas.suffolk.edu/moin/O...page=main.html

    it probably could help you
    (however it doesn't contain designer)

  12. #12
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by pthomas
    ... snip ...
    Any kind souls out there?
    Paul
    You may think me not so kind after you read this, but here is what I wrote to introduce other programmers around here to QT4 and C++.

    When you read it, remember that it is about the FIRST C++/QT4 app I ever wrote. I've attached it as a "bz2" file but after you download it rename it and give it a ".zip" extension because it is a zip file.
    HOWTO_html_zip.bz2
    Note: "bz2" file updated on 1/31/2005 with GPL msg and converted to an HTML file, then reloaded because the zip contained only the images, not the html. Everything should be ok now.
    Last edited by GreyGeek; 31st January 2006 at 21:21. Reason: HTML version with Chicken Blood's Edits.

  13. #13
    Join Date
    Jan 2006
    Location
    New Malden (near London)
    Posts
    32
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by pthomas
    What type of IDE or what programs do you use for your Qt development stuff? It seems like the best way so far might just be a combination of the Qt Designer for dialogs and main windows + Kate for code editing.

    Is there another good combination/IDE that you would recommend?
    Paul
    I don't think there is one, right now. KDE 4 is not due out until towards the end of this year, although it's likely that KDevelop will start supporting Qt4 projects before then (at least, I hope they would). I do most of my development with Emacs (recent versions I've used don't seem to have the formatting versions which were a pain in the backside when writing Q_OBJECT header files in particuar), and compile with qmake and make.

  14. #14
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by wysota
    Actually you can't. At least not in my definition of the word "manage". I mean a Qt project not a KDE one. Qt projects are managed by QMake, not by automake and KDevelop's QMake project manager doesn't support Qt4 at all. I'd even say in anti-supports it, as it breaks Qt4 project files and you can't do anything about it. You can't even compile a project using Qt4 out of the box. The only thing that works there is providing proper include names while defining superclasses to a class. I know KDevelop is a KDE project and KDE people use automake instead of QMake, but in my opinion "support" is not about using one of the undocumented options to make something work but to work by default (it's not documented anywhere that this "support" concerns only automake based projects).
    I would be interested in hearing your definition of the word manage. I am using Kdevelop 3.3, and using it for my QT4 stuff quite well. It won't compile the included sample app, but it is compiling my QT4 projects just fine. Granted, I did set QT4 in the options box for the project options.

    I'm using qmake, and so far everything works just fine for me. When I click the build project button on a new project it tells me I need to run qmake first, and then asks me if I want to go ahead and do that. How is that broken or not using qmake? If I make clean and/or take my .pro along with headers and code files, move them all to a new directory, run qmake then make, it all wokrs[1] just fine.

    Maybe something somewhere is broken I'll grant indeed as noted above something is. As I am new to Qt and Kdevelop (not to mention KDE .. I've tried it every few years for a long time but until now never for this long), I'd be interested in exactly how the above behaviour is broken .. mainly so I know what to expect when said behaviour is "fixed".

    And in the event someone asks, it's Gentoo and kde3.5.

    Cheers

    1: works

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed

    For example try adding a resource file to your project using KDevelop. Or add it manually to the project file, then load it into KDevelop and do something so that the project file gets saved by KDevelop. Then look at the resulting .pro file.

    Another example -- try turning on or off some of the modules from Qt (like gui, xml or whatever). Or try to do it manually in the project file and then open KDevelop and make it resave the file. Then look at it. You can repeat that for every feature which is not present in Qt3.

    Third example -- install Qt3 development files along Qt4 development files. Make sure that Qt3 files are ahead of Qt4 ones in your $PATH and then try to tell KDevelop to compile using Qt4 without changing the $PATH.

    Fourth example -- did it install Qt4 documentation so that you can use it from KDevelop's integrated documentation browser? Do you see both Qt3 and Qt4 documentation in the tree there?

    If you want more examples, drop me a line.

    What is more funny -- there is an entry somewhere in the configuration dialog of KDevelop to set the path to qmake. Well... the funny part is, that KDevelop never checks that when looking for qmake. It has some paths hardcoded, so if you have qmake in some non-default location, it won't find it.

  16. #16
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    What is more funny -- there is an entry somewhere in the configuration dialog of KDevelop to set the path to qmake. Well... the funny part is, that KDevelop never checks that when looking for qmake. It has some paths hardcoded, so if you have qmake in some non-default location, it won't find it.
    That is strange.
    Mine uses QTDIR , not hard coded, as can be seen from the first build line:
    cd '/home/kish/vision/projects/autotracker/src' && QTDIR="/usr/lib/qt3" gmake -k -j1 clean && QTDIR=&q

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by theLSB
    That is strange.
    Mine uses QTDIR , not hard coded, as can be seen from the first build line:
    Do you use a vanilla kdevelop or an rpm from some distro? Besides, /usr/lib/qt3 is one of the hardcoded paths to look for Qt (as among other, mdk uses it).

    QTDIR="/usr/lib/qt3" gmake -k -j1 clean
    Try setting a custom QTDIR before running KDevelop and it'll still use /usr/lib/qt3. It's because it sets QTDIR on its own, overriding all that has been set before. So the only way I found to make KDevelop (or rather TrollProjectPart) compile using Qt4 is to put Qt4 qmake in front of Qt3 qmake in $PATH.

    I'm just rebuilding KDevelop rpm, so I have its sources with me:

    Qt Code:
    1. bool TrollProjectPart::isValidQtDir( const QString& path ) const
    2. {
    3. return QFile::exists( path + "/include/qt.h" );
    4. }
    5.  
    6. QStringList TrollProjectPart::availableQtDirList() const
    7. {
    8. QStringList qtdirs, lst;
    9. qtdirs.push_back( ::getenv("QTDIR") );
    10. qtdirs.push_back( "/usr/lib/qt3" );
    11. qtdirs.push_back( "/usr/lib/qt" );
    12. qtdirs.push_back( "/usr/share/qt3" );
    13.  
    14. for( QStringList::Iterator it=qtdirs.begin(); it!=qtdirs.end(); ++it )
    15. {
    16. QString qtdir = *it;
    17. if( !qtdir.isEmpty() && isValidQtDir(qtdir) )
    18. lst.push_back( qtdir );
    19. }
    20. return lst;
    21. }
    To copy to clipboard, switch view to plain text mode 

    You could say -- "Ok, so it reads QTDIR env, so it should work". Well... yes, but not for Qt4. Look at how it check for valid QTDIRS -- it looks for $QTDIR/include/qt.h and with Qt4 no such file exists... A workaround would be to create one of course, but there are better ways to check for a Qt installation than scanning for $QTDIR/include/qt.h which may not be valid even for Qt3 (some distros keep Qt include files inside /usr/include/), so a patch is needed for different distros.

    Anyway it doesn't look for Qt in a place, which was entered by the user in the configuration dialog.

  18. #18
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    Do you use a vanilla kdevelop or an rpm from some distro?
    SUSE10 KDevelop 3.3.x (can't remember not on that machine at the moment)
    Try setting a custom QTDIR before running KDevelop and it'll still use /usr/lib/qt3. It's because it sets QTDIR on its own, overriding all that has been set before.
    I actually did, two days ago, since my enviorment was abit messed up, and it didn't work, meaning, KDeveloped whent to the QTDIR and could not find qmake, or was it moc, I can't remembet now any more, but it could not compile at all.
    You could say -- "Ok, so it reads QTDIR env, so it should work".
    Actually no, I am not yet in to that discussion.
    I didn't try enough to say "I know it".
    All I know, is, that the first time I installed SUSE10 I noticed it installed Qt4 and Qt3 by defalut.
    I tried beifly to compile a Qt4 project in KDevelop, it worked ok, but I didn't try fancy things with it, so I don't know how well it would have behaved.
    Since then I uninstalled Qt4, and when I tried to install it back, yast2 messed up my KDE.
    So my next try (once I find a bit of time) is to compile my self Qt4 and install it my self, with out letting yast mess up things.

  19. #19
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by wysota
    ...but there are better ways to check for a Qt installation than scanning for $QTDIR/include/qt.h which may not be valid even for Qt3 (some distros keep Qt include files inside /usr/include/), so a patch is needed for different distros...
    Could you please elaborate more on that? What would be a better way? I'm relying heavily in QTDIR, and as I can see it's still there in my Qt 4.1.0 windows installation. On my linux box I'm still with 3.3.5

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Basic Qt4 tutorial needed

    Quote Originally Posted by yop
    Could you please elaborate more on that? What would be a better way? I'm relying heavily in QTDIR, and as I can see it's still there in my Qt 4.1.0 windows installation. On my linux box I'm still with 3.3.5
    I meant defining a QTDIR as "a directory which has an 'include/qt.h' file inside". This file is not present in Qt4. And it doesn't have to be present there in Qt3 too.

    There is also a question what to define by a "QTDIR". The directory which holds includes? One which holds plugins? What if there are no plugins? Binaries maybe? What if they are in /usr/bin/? Mkspecs files maybe? But they can be elsewhere too...

    Qt4 doesn't use "QTDIR" anymore. I guess the path is somehow hardcoded into qmake or mkspecs files.

Similar Threads

  1. QtScript basic tutorial
    By thomir in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2013, 04:17

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.