PDA

View Full Version : QString in Visual Studio 2005 has compile error



KaKa
13th March 2007, 11:23
I was trying to extract the text from the LineEdit generated in QT designer embedded in Visual Studio 2005.
So it returns QString, so I had to manipulate the QString.

However, this gives a compile error:

ClientProject error LNK2019: unresolved external symbol...

From MSDN I noticed that it is due to the incompatibility of CString derived class with VS,
Detail see the following web page:

http://support.microsoft.com/kb/309801

The page has included a resolution for ATL. But what is the resolution for QT???

I am in urgent need of a resolution!!!

Thanks a lot!!! :crying:

high_flyer
13th March 2007, 11:37
Although the problem may indeed be an exotic one like you claim (i.e some problem with CString), I would first tend to think you are not liking correctly.
It would be helpful to see your code.
Can you compile successfully other Qt code with VS2005?

KaKa
13th March 2007, 12:14
Thanks very much for replying!

I can compile well with other code.
And this problem only occurs when I uncommented the two lines:

*a=ui.lineEdit_2->text();
*b=ui.LineEdit-3>text();
where a and b are declared as QString*, and have been inistialized using QString() before.

Are these things above useful?

Thanks a lot!

high_flyer
13th March 2007, 12:50
Hmm... hard to tell - can you show a bit more code, the whole function that contains the above code for example?
I see you are using ui, I guess its a designed class implementation, did you do setupUi()?

KaKa
14th March 2007, 03:32
Thanks very much again for replying my post, here is some more detailed description of my code:

1. many of the code was generated automatically after I drew widgets using the VS embedded QT designer, ui is one of them, and the function you mentioned is there and it is automatically generated.

2. Before showing your the code I hope to say: so basically the logic of this portion of code is:
I have a QEditLine widget, which has the .text() function to retrieveQString, and I was using declared QStrings to get the .text and send it over to another logic part (declared as a QObject class(the aLogic class below)) to parse those strings(will need to convert the QStrings to char array) but it didn't even go throught the part of the QObject class that checks if the QString passed in are Null.

So below is the code:

I. Class set a:

a.h:

class a : public QDialog
{
Q_OBJECT

QString *param1;
QString *param2;


public:
a(QWidget *parent = 0);
~a();


private:
Ui::aClass ui;

private slots:
void on_OK3_clicked();
void on_Reset3_clicked();
};

a.cpp:

a::a(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}

a::~a()
{

}


void a::on_Reset3_clicked()
{
ui.lineEdit_2->clear();
ui.RestLineEdit->clear();
}

void a::on_OK3_clicked()
{
param1=new QString();
param2=new QString();
*param1=ui.lineEdit_2->text();
*param2=ui.RestLineEdit->text();
aLogic *theapp=new aLogic();
int success=theapp->checkaLogic(*param1);
}

II. Class set aLogic:

aLogic.h:

class aLogic : public QObject
{
Q_OBJECT

QObject *Logicparent;

public:
aLogic();
aLogic(QObject *parent);
~aLogic();
int checkaLogic(QString b);

private:
};

aLogic.cpp:

aLogic::aLogic(QObject *parent)
: QObject(parent)
{
Logicparent=parent;
}

aLogic::~aLogic()
{

}


int aLogic::checkaLogic(QString b)
{
if(b.isNull())
{
QMessageBox *warmessage=new QMessageBox();
warmessage->setText("Please enter a string");
warmessage->setIcon(QMessageBox::Critical);
return 0;
}

return 0;
}

Note that in the aLogic class set I wanted to declare param1 and param2 to be type of QString, but because the compiler was complaining that the constructor QString() should return a pointer, so I made param1 and param2 pointers.

Sorry this is so long...but I am just in such a hurry.

Thanks very much! :)

vermarajeev
14th March 2007, 03:54
Did you connect clicked() signal to your slots???? If not first do that. I dont have Qt4 installed on my system and it is just a guess by seeing your post by reading this statement
but it didn't even go throught the part of the QObject class that checks if the QString passed in are Null.

high_flyer
14th March 2007, 08:58
1. many of the code was generated automatically after I drew widgets using the VS embedded QT designer, ui is one of them, and the function you mentioned is there and it is automatically generated.
What do you mean by that? - did you change any of the designer genrated code?
Are you sure you are mocing all your QObject classes?
Did you include the ui_<class>.h generated by designer?

Oh, and please - use the code quotes for code, it really is hard to read it like that - thanks.

KaKa
14th March 2007, 09:56
I finally found the problem.

I forgot to define the default constructor.

Thanks for paying all the attention.

And sorry for bothering high_flyer so much. I really feel guilty now :(.

high_flyer
14th March 2007, 10:05
It is no bother - and don't feel guilty!
You can PM me any time - but use the PM for things that do NOT concern the forum.
Posts and Qt questions are very much of iterest to the forum, so their place is here and not in a PM, this way every one can benfit from them! :)