# Help with QTextEdit.

• So, I'm trying to follow this tutorial in Visual C++ 2010, only the only thing I would say is, "Hello World!"

http://wiki.forum.nokia.com/index.php/How_to_use_QSplitter_and_QTextEdit_in_Qt

I recreated the splitter.h from here since it appears to need that:
http://stackoverflow.com/questions/3888611/qt-separator-widget

...&, of course, it's not working. Anyone wanaa help? You can download the source here:

Thank you,
M260

• First a hint for posting:

Thanks for providing the source code, it helps in searching the problem. But please do not include object and build files for your platform/compiler/IDE. Your download is about 18 MB, which is quite big for four sources files in the end ;-)

It makes your life much more easier and will most probably lead to more people reading your post and thinking about your problem.

So, regarding your actual problem. This is nothing directly Qt related, more sort of some general issues with C++. I suppose you are new to C++, as these kind of errors are very common, every programmer stumbles over them once in a while, even the most skilled ones.

I'll post the code here to ease the analysis:

--- splitter.h ---

@
#ifndef SPLITTER_H
#define SPLITTER_H

#include <QtGui/QDialog>

class splitter : public QDialog
{
Q_OBJECT;

QWidget*        widget1;
QWidget*        widget2;

QPushButton*    button;


public:
splitter(QWidget *parent = 0, Qt::WFlags flags = 0);
~splitter();

private slots:
void showHide(void);
};

#endif // SPLITTER_H
@

@
#include "splitter.h"
#include<QSplitter>
#include<QTextEdit>
#include<QHBoxLayout>

: QMainWindow(parent, flags)
{
ui.setupUi(this);
}

{

}

splitter::splitter(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *layout=new QHBoxLayout(this);
QTextEdit editor1 = new QTextEdit("Hello World",this);QSplitter splitter(Qt::Vertical);
setStyleSheet("
{ background-color:rgb(0,0,0);color:rgb(255,255,255); padding: 7px}}");

setLayout(layout);
showMaximized();
}
@

You have several errors here, I post the messages from gcc (on a Mac). You are on Windows using Visual Studio, so the error messages are different, but should be worded similar.

bq. projectisthisabadgame.cpp:18: Error:prototype for 'splitter::splitter(QWidget*)' does not match any in class 'splitter'

Look at the declaration of the constructor in splitter.h line 16:

@
splitter(QWidget *parent = 0, Qt::WFlags flags = 0);
@

and compare with the signature of the constructor you actually implemented in projectisthisabadgame.cpp:

@
splitter::splitter(QWidget *parent)
: QWidget(parent)
{
// ...
}
@

You see: you declared a constructor with two parameters, but implemented it with only one parameter. You can add the second parameter in the .cpp or remove the second one in the .h. Go with the first, as this is the same signature as the standard constructor of "QDialog":http://doc.qt.nokia.com/4.7/qdialog.html#QDialog.

This ist the correct constructor signature:

@
splitter::splitter(QWidget *parent, Qt::WFlags flags)
: QWidget(parent)
{
// ...
}
@

Another compiler run gives us the next error message:

bq. projectisthisabadgame.cpp:19: Error:type 'class QWidget' is not a direct base of 'splitter'

This is easy to fix, too. In splitter.h you declared class splitter to inherit from QDialog. In the implementation you call a QWidget constructor (which is a base class of QDialog; line 19 in projectisthisabadgame.cpp). But this is wrong, you must always call the constructors of the direct base class in your own constructors. So, change this to:

@
splitter::splitter(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
// ...
}
@

Also, notice the handing over of the second parameter (flags) to QDialog's constructor.

Your code now compiles without errors. The next errors are popped up by the linker (which does not compile anything, but puts the previously compiled little pieces together to the final application).

bq. Undefined symbols: splitter::~splitter() and splitter::showHide()

In your splitter.h you declared a destructor ~splitter() (line 17) and a method showHide() (line 20), but you did not provide an implementation in your .cpp file. Just add some dummy implementation in the .cpp:

@
splitter::~splitter()
{
}

void splitter::showHide()
{
}
@

Please note that a parameter-less method takes no argument. It's not an error to write showHide(void), but most programmers consider this as unnecessary chatter. Better omit it.

Your code now compiles and links without errors.

Just another tip: In your project you have splitter.h and projectisthisabadgame.h declaring the classes. You implement both in projectisthisabadgame.cpp. This works, no question, but it is not a good idea. Better to separate your classes' implementations into separate files too (i.e. move the splitter stuff into a new file splitter.cpp)

Feel free to come back with further questions.

• Thank you! :D

• Sry, but I seem to get a, "cannot open file, 'QTHelpd4.lib,'" error, even after compiling Qt from source...

Thank you :D
M260

• Did you add

@
CONFIG += help
@

to your .pro file?

• Thanks, I'll try it!

EDIT: Well, you see, I'm pretty sure Visual Studio uses plain ol' cpp files instead of pro files, just like normal C++. So, I added it to the end of projectisthisabadgame.cpp & got this output:

@1>------ Build started: Project: Project Is This a Bad Game, Configuration: Debug Win32 ------
1>Build started 4/17/2011 10:32:12 AM.
1>InitializeBuildStatus:
1> Touching "Debug\Project Is This a Bad Game.unsuccessfulbuild".
1>CustomBuild:
1> All outputs are up-to-date.
1>ClCompile:
1>projectisthisabadgame.cpp(39): error C2143: syntax error : missing ';' before '+='
1>projectisthisabadgame.cpp(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.26
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========@

Can anyone help?

Thanks,
M260

• Show us your projectisthisabadgame.cpp please, in particulary from line 37 - 40

• Well, actually, an old version is shown earlier in this thread, but here's an updated version:

#include "splitter.h"
#include<QSplitter>
#include<QTextEdit>
#include<QHBoxLayout>

: QMainWindow(parent, flags)
{
ui.setupUi(this);
}

{

}

splitter::splitter(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
QHBoxLayout *layout=new QHBoxLayout(this);
QTextEdit editor1 = new QTextEdit("Hello World",this);QSplitter splitter(Qt::Vertical);
setStyleSheet("
{ background-color:rgb(0,0,0);color:rgb(255,255,255); padding: 7px}}");

setLayout(layout);
showMaximized();
}

splitter::~splitter()
{
}

void splitter::showHide()
{
}

CONFIG += help@

EDIT: Um, the forum messed up the formatting a bit I think, but, whatever...

• Line 39!!!!

@CONFIG += help@

got to be removed from this file and add it into your .pro file, try to recompile then.

• But the reason I added it there is because it seems Visual Studio doesn't support pro files...

• I think that you got to generate it with qmake.exe and add it in your links, i'll search more infos for later, stand by mate

• You can use the "Visual Studio Add-in":http://qt.nokia.com/downloads/visual-studio-add-in to manage the mapping between .pro files and Visual Studio project files. The manual is "here":http://doc.qt.nokia.com/vs-add-in-1.1.7/index.html.

• OK, here is the deal:
You have to generate a .pro file with 'Qt command prompt' (look into qt root folder)
Start Qt Command prompt and enter following commands:

-> cd c:\Folder\of\your\project\ (directory that contains Visual studio's project file)
-> qmake -project
-> qmake

after these commands look into your project folder, you'll see some auto generated files and folders, and .pro file will be there, just edit it however you want.

If you want to compile just continue with the following command:
-> make

• Thanks, but after doing qmake, this happened:

http://i55.tinypic.com/ivzpcp.png

• A couple of warnings - nothing to worry about. What happens after running nmake?

• Is your project compiled?

By the way, use preferably directories without spaces for your projects, very important!
Never use spaces, compilator might show you some errors.

• [quote author="Azr79" date="1303931305"]Is your project compiled?

By the way, use preferably directories without spaces for your projects, very important!
Never use spaces, compilator might show you some errors.[/quote]

Well, it's never compiled succesfully since everything in ths thread's happened... (Not to be rude.)

• why not using QtCreator? There is no problems with it, because already configured for qt projects....

• [quote author="Azr79" date="1303944734"]why not using QtCreator? There is no problems with it, because already configured for qt projects....[/quote]
The problem is it doesn't seem to be friendly with what I'm trying to do.

• Do you have your old vcproj file stored somewhere?
If you want to add a lib in MSVS, use the MSVS way, even for Qt libs:

open project settinbs, go to linker --> input page and add the file

• Open the Visual Studio command shell and run:

@
cd c:\path\to\your\project
qmake -project
@

Then install the Visual Studio add in (link mentioned earlier) and restart VS, if you did not before.

Then open Visual Studio.

Then open menu Qt / Qt Options and check if your Qt version is listed there. If not, add it!

Now create a new solution, open Menu Qt / Open qt project file (.pro) and select the newly created .pro from the first step.

Your setup is basically complete now.

OR

Create a new solution, add a new project and select one of the Qt4 project templates (Qt4 Application most likely) and just add your source, header and ui files.

In both cases, it might help if you start in a fresh new directory, where you copy in just the .h, .cpp, .ui files before calling qmake -project or creating the new Qt4 project.

• Well, I made a pro, except it still got the same error after I added the CONFIG += help

However, I noticed that the pro was in place of the vcxproj, a.k.a. the Visual Studio Solution. Also, I noticed that the pro already contained CONFIG += [a bunch of stuff] help [another bunch of stuff] This seems to indicate that the CONFIG += help... was already there...

So, it doesn't seem to be the problem. Any more help? Thanks for all the help so far, BTW. (Not to be rude.)

Thnk you,
M260

• If you just change the .pro and do nothing else, the VS project is not changed. What about the steps mentioned in my previous comment?

• [quote author="Volker" date="1304027822"]If you just change the .pro and do nothing else, the VS project is not changed. What about the steps mentioned in my previous comment?[/quote]
Well, I've already done all that - unless you really think I should just start a new project & re-add everything... (Not to be rude.)

• I would try to start from scratch in a fresh, empty directory. Just copy the sources (h, cpp, ui). Make a directory without spaces in it to eliminate this problem. Then run qmake -project and import the .pro with the VS addin.

Be sure you have setup the Qt versions in the addin!

• 1st of all, sorry it's taken me months to reply? Anyways, Volker, can I just have the actual files from when you 1st successfully compiled it as described in your 1st posst? I know I won't be able to use Visual Studio.

• Sorry, I did not keep the files for that long.

• [quote author="Volker" date="1312234572"]Sorry, I did not keep the files for that long.[/quote]

It's okay, I think I might've found something else I can do. Than you, though!

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.