PDA

View Full Version : tvtenniss.qml



s.bolboli
15th April 2012, 12:50
hi
I wanna run tvteniss qt example in neatbeans>c++>qapplication
I know I should use QDeclarativeView for binding qml to c++ but the out put is: QDclarativeview: No such file or directory
what can I do?
how can I run this example in qapplication?

Zlatomir
15th April 2012, 12:54
Do you have QT += declarative into your .pro file?

s.bolboli
15th April 2012, 18:29
yes I add it to C:\Qt\4.8.0\examples\declarative\toys\tvtennis.pro
and also in my own program.
I should do this project in C++>qapplication?and then I have three file main.cpp,tvtennis.cpp,tvtennis.h?
plz answer my question as soon as possible:(

Zlatomir
16th April 2012, 11:09
I checked that example and it seems that it is just shows you exactly what you need (if i correctly understood what you need - to show that qml file in an Qt application - it just does much more stuff and has a "wrapper-class" that manages screen orientation and other stuff).

Anyway in netbeans you need to add Qt modules by checking them in:
- project's Properties in the Qt category: check Declarative there (it may require a rebuild all)

But why are you using Netbeans and not Creator?

s.bolboli
16th April 2012, 12:14
thank u so mush for ur help.
I should make tvtennis with c++ and with qapplication.
I add QDeclarativeView inMyproject>properties>linker>library but unfortunately nothing change
my code in main.cpp is these:

#include <QtGui/QApplication>
#include<QPushButton.h>
#include<qfont.h>
#include<qapplication.h>
#include<qslider.h>
#include<qlcdnumber.h>
#include<QApplication>
#include<QDeclarativeView>
#include<QDeclarativeContext>

#include"tvtennis.h"


class MyWidget : public QWidget
{
public:
MyWidge(QWidget *parent=0,const char *name=0);
};
MyWidget::MyWidget(QWidget *parent,const char *name):QWidget(parent,name)

{

QPushButton *reset("Reset",0);
reset.resize(70,30);
reset.setFont(QFont("Times",18,QFont::Bold))
QObject::connect(&reset,SIGNAL(clicked()),this ,SLOT(reset()));
//app.setMainWidget(&reset);
QLCDNumber *lcd1 =new QLCDNumber(2,this,"lcdNumber1");
QLCDNumber:: connect(QLCDNumber,SIGNAL(valueChanged(int),lcdNum ber1,SLOT(display(int))));

QLCDNumber *lcd2=new QLCDNumber(2,this,"lcdNumber2");
QLCDNumber::connect(QLCDNumber,SIGNAL(valueChanged (int),lcdNumber2,SLOT(display(int))));

reset->show();
lcd1->show();
lcd2->show();
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QDeclarativeView view;
QDeclarativeContext *context=view.rootContext();
view.setScene(QUrl::fromLocalFile("tvtennis.qml"));
//Mywidget w;

view.show();

return app.exec();
};


and error is: fatal error: QDeclarativeView: No such file or directory

Zlatomir
16th April 2012, 13:49
I was talking about this: http://netbeans.org/images_www/articles/69/cnd/qt/qt-project-properties.png
not only linker/library (since you need the headers too - that is what you are missing now)

BTW why are you including both QtGui/QApplication and qapplication.h?
LE: The qml is loaded to the view with setSource (http://doc.qt.nokia.com/4.7/qdeclarativeview.html#source-prop)

s.bolboli
16th April 2012, 16:05
project properties>Build>Qt same as above link.
As same as setSource represent first of all I should add #include <QDeclarativeView> but my program doesn't know that.
now my problem is declare #include <QDeclarativeView> to main.cpp.
added QT +=QDeclarativeView in .pro didn't change anything
I couldn't find any solution in google and Qt assistant
what shall I do?

Zlatomir
16th April 2012, 16:27
project properties>Build>Qt same as above link...
Did you checked "declarative" there and then "Rebuild All" - or whatever "Rebuild all" might be called in Netbeans?

what shall I do?
If you did the above check - i'm out of ideas... maybe use Creator and stop using Java tools for C++... Netbeans might be good for Java coding, but i never heard anyone recommend it for C++ development.

wysota
16th April 2012, 22:24
Is this some kind of homework or school project?

s.bolboli
17th April 2012, 07:58
Like this,but there isn't any force to do it but because working whit qt & netbeans together is interesting for me i wanna to solve it
what's the problem?

wysota
17th April 2012, 08:06
There is no problem. It's just we can't give complete solutions for homeworks, only hints.

Are you using qmake to compile your program?

s.bolboli
17th April 2012, 08:11
if it's mean that i enter QDeclarative in intermediate file>UI Directory I do this and Rebuild project (However in ur link isn't it) and the output is:

nbproject/Makefile-variables.mk:15: *** missing separator. Stop.


BUILD FAILED (exit value 2, total time: 53ms)
and still #include<QDeclarativeView> , #include<QDeclarativeContext> are unknown

yes I do and I do this but I don't know why netbeans doesn't know #include<QDeclarativeView>,#include<QDeclarativeContext>
i didn't want a code for tennis program

yes I use qmake to compile it

wysota
17th April 2012, 10:55
Did you rerun qmake after adding the declarative module to the .pro file? The proper line is QT+=declarative and not QT+=QDeclarativeView

s.bolboli
17th April 2012, 15:24
If it's mean that rerun it in C:\Qt\4.8.0\bin\qmake I do it,
I add QT+=declarative and not QT+=QDeclarativeView
I run the project in c++>qapplication>main.cpp and also I have 3 file(main.cpp,tvtennis.cpp,tvtennis.h) it's true?
it also doesn't know #include<qmlapplication>

wysota
17th April 2012, 15:48
Do you have a file called qmlapplication anywhere?

s.bolboli
17th April 2012, 16:50
I have qmlapplicationviewer

wysota
17th April 2012, 21:15
So if you don't have a qmlapplication file, then obviously including that file will fail.