You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

1

Monday, November 21st 2005, 7:31pm

Qtextbrowser

Hi,all I am a new hand of QT.
I want to wrire a simple program like this.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<qapplication.h>
#include<qtextbrowser.h>
#include<qlabel.h>
#include<qstring.h>
int main(int argc,char *argv[])
{
	QApplication app(argc,argv);
	QWidget *mywidget = new QWidget;
	QTextBrowser browser = new QTextBrowser(0);
	browser.setSource(QString("http://tw.yahoo.com"));
	app.setMainWidget(mywidget);
	mywidget->show();

	return app.exec();
}


but when I complie it something wrong happen.

/usr/lib/qt3-gcc3.2/include/qtextbrowser.h: In function `int main(int,
char**)':
/usr/lib/qt3-gcc3.2/include/qtextbrowser.h:91: `
QTextBrowser::QTextBrowser(const QTextBrowser&)' is private
browser.cpp:9: within this context
browser.cpp:9: initializing temporary from result of `
QTextBrowser::QTextBrowser(QWidget*, const char*)'
make: *** [browser.o] Error 1


what wrong with my program and how should i modify it?? ?( ?(

thanks all.

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Monday, November 21st 2005, 7:37pm

RE: Qtextbrowser

Try:

Source code

1
2
3
4
QTextBrowser browser;
browser.setSource( QString( "http://tw.yahoo.com" ) );
app.setMainWidget( &browser );
browser.show();
or

Source code

1
2
3
4
QTextBrowser *browser = new QTextBrowser();
browser->setSource( QString( "http://tw.yahoo.com" ) );
app.setMainWidget( browser );
browser->show();

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

3

Monday, November 21st 2005, 8:10pm

RE: Qtextbrowser

Compiler is OK!!

but the webpage can't display.

what should I do?

When I execute it some message dispaly
QTextBrowser: no mimesource for http://tw.yahoo.com

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

4

Monday, November 21st 2005, 8:33pm

RE: Qtextbrowser

Quoted

Originally posted by note1
When I execute it some message dispaly
QTextBrowser: no mimesource for http://tw.yahoo.com

QTextBrowser doesn't know anything about the Internet (in fact it can only display a subset of HTML), so it can't download any files. Instead it asks the QMimeSourceFactory instance for the file.

QMimeSourceFactory by default reads files from the hard drive, but you can implement your own factory that reads data using QHttp or QUrlOperator.

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

5

Tuesday, November 22nd 2005, 6:24am

RE: Qtextbrowser

Sorry my English is not good enough...

you mean :

First:I should use Qhttp or Qftp to download the webpage in my hard disk

Second:I use QMimeSourceFactory to read the webpage in my hard disk?? ?(

?( ?( ?(

This post has been edited 1 times, last edit by "note1" (Nov 22nd 2005, 6:29am)


jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

6

Tuesday, November 22nd 2005, 9:43am

RE: Qtextbrowser

Quoted

Originally posted by note1
First:I should use Qhttp or Qftp to download the webpage in my hard disk
Second:I use QMimeSourceFactory to read the webpage in my hard disk??

If you download the web page to the hard disk, QTextBrowser::setSource() will be enough.

Create a HTML document, save it as "test.html" in the same directory where your application is and try this:

Source code

1
browser.setSource( QApplication::applicationDirPath() + "/test.html" );

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

7

Thursday, November 24th 2005, 9:14am

RE: Qtextbrowser

Hi, all
I want to download the webpage in my hard disk

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<qapplication.h>
#include<qtextbrowser.h>
#include<qlabel.h>
#include<qhttp.h>
#include<qfile.h>
int main(int argc,char *argv[])
{
        QApplication app(argc,argv);
        QWidget *mywidget = new QWidget;
        //QTextBrowser *browser = new QTextBrowser;
        QHttp *http = new QHttp();
        QFile *file = new QFile("index.html");

        http->setHost("http://tw.yahoo.com");
        http->get("index.html",&file);

        app.setMainWidget(mywidget);
        mywidget->show();
        return app.exec();
}


But I complier it.
Eroor message happen

browser.cpp: In function `int main(int, char**)':
browser.cpp:16: no matching function for call to `QHttp::setHost(const char[20]
)'
browser.cpp:17: no matching function for call to `QHttp::get(const char[11],
QFile**)'
make: *** [browser.o] Error 1



What should I do?? ?( ?(

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

8

Thursday, November 24th 2005, 3:19pm

RE: Qtextbrowser

Quoted

Originally posted by note1
What should I do?? ?( ?(

Add "#include <qstring.h>".

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

9

Thursday, November 24th 2005, 5:00pm

RE: Qtextbrowser

;( ;(
the compiler have the same error..

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

10

Thursday, November 24th 2005, 5:04pm

RE: Qtextbrowser

Remove '&' from this line:

Source code

1
http->get("index.html",&file);

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

11

Thursday, November 24th 2005, 5:14pm

RE: Qtextbrowser

the same error when compiler...

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

12

Thursday, November 24th 2005, 5:15pm

RE: Qtextbrowser

Quoted

Originally posted by note1
the same error when compiler...

Could you post this error message?

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

13

Thursday, November 24th 2005, 5:20pm

RE: Qtextbrowser

The error message is

g++ -c -pipe -Wall -W -I/usr/include/fontconfig -I/usr/include/Xft2 -O2 -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt3-gcc3.2/include -I/usr/lib/qt3-gcc3.2/mkspecs/default -o browser.o browser.cpp
browser.cpp: In function `int main(int, char**)':
browser.cpp:16: no matching function for call to `QHttp::setHost(const char[20]
)'
browser.cpp:17: no matching function for call to `QHttp::get(const char[11],
QFile*&)'
make: *** [browser.o] Error 1

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

14

Thursday, November 24th 2005, 5:26pm

RE: Qtextbrowser

This isn't the same error message which you posted before! Where did you add "#include <qstring.h>"?

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

15

Thursday, November 24th 2005, 5:31pm

RE: Qtextbrowser

This is my code

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<qapplication.h>
#include<qtextbrowser.h>
#include<qlabel.h>
#include<qstring.h>
#include<qhttp.h>
#include<qfile.h>
#include<qurloperator.h>
int main(int argc,char *argv[])
{
        QApplication app(argc,argv);
        QWidget *mywidget = new QWidget;
        //QTextBrowser *browser = new QTextBrowser;
        QHttp *http = new QHttp();
        QFile *file = new QFile("index.html");

        http->setHost("http://tw.yahoo.com");
        http->get("index.html",file);

        app.setMainWidget(mywidget);
        mywidget->show();

        return app.exec();
}

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

16

Thursday, November 24th 2005, 5:34pm

RE: Qtextbrowser

It compiles without any problems on my system. Are you sure that you try to compile this particular version of your source code?

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

17

Thursday, November 24th 2005, 5:45pm

RE: Qtextbrowser

I use QT3.2 and My OS is Redhat9.0

My file name is "browser.cpp"
and I do these step

1.qmake -project browser.pro
2.qmake browser.pro
3.make

This post has been edited 1 times, last edit by "note1" (Nov 24th 2005, 5:45pm)


jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

18

Thursday, November 24th 2005, 5:53pm

RE: Qtextbrowser

Try this:

Source code

1
2
http->setHost( QString( "tw.yahoo.com" ) );
http->get( QString( "index.html" ), file );

note1

Beginner

  • "note1" is male
  • "note1" started this thread

Posts: 35

Location: Taiwan

Occupation: student

  • Send private message

19

Thursday, November 24th 2005, 6:05pm

RE: Qtextbrowser

Un~I try it.But the same error.

I see my "qhttp.h" file

It isn't like the http://doc.trolltech.com/3.3/qhttp-h.html

Can you give me this file "qhttp.h" ?

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

20

Thursday, November 24th 2005, 6:47pm

RE: Qtextbrowser

Quoted

Originally posted by note1
Un~I try it.But the same error.

Are you 100% sure that you get exactly the same error? Could you post it?

Quoted

I see my "qhttp.h" file

It isn't like the http://doc.trolltech.com/3.3/qhttp-h.html

Because this is a file from Qt 3.3, not Qt 3.2. But according to the Qt 3.2 docs your program should compile.

Quoted

Can you give me this file "qhttp.h" ?

It won't be enough, if you want some class from Qt 3.3, you have to install whole Qt 3.3.