You are not logged in.

Guest

Unregistered

1

Tuesday, March 22nd 2005, 8:28am

Is there a QT command to lunch the default web browser (Win/MacLinux) ?

Is there a QT command to lunch the default web browser (Win/MacLinux) to view a website or a html page on hard disk ?

zlatko

Professional

  • "zlatko" is male

Posts: 728

Location: Ukraine,Lviv

Occupation: programmer

  • Send private message

2

Tuesday, March 22nd 2005, 8:40am

some monyhs ago i have such problem...but i didnt find solution.
i use QProcess for start internet explorer :(
a life without programming its alike empty bottle 8)

bisserke

Beginner

  • "bisserke" is male

Posts: 32

Location: Belgium

Occupation: Right now my job is eatin' these doughnuts, or maybe...

  • Send private message

3

Tuesday, March 22nd 2005, 9:39am

nope.
but you can use this: (at least for WIN32 platforms. The *NIX counterpart can be looked up)

Source code

1
2
3
4
5
6
7
QString url = "http://www.trolltech.com"

#ifdef WIN32
	HWND mainwndw = winId();
	HINSTANCE status =::ShellExecute( mainwndw, NULL, ( TCHAR * ) qt_winTchar( url, true ), NULL, NULL, SW_SHOW );

#endif


the winId is a member of the QWidget class. So you can also pass NULL instead of mainwndw
Documentation is like sex: when it is good, it is very, very good. And when it is bad, it is better than nothing. - Dick Brandon

This post has been edited 1 times, last edit by "bisserke" (Mar 22nd 2005, 9:42am)


Barney`

Beginner

  • "Barney`" is male

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

4

Wednesday, June 15th 2005, 7:13pm

I want to launch the help html pages (in a repertory of the hdd) of the project I'm creating by clicking on the "Help" option in the menu bar. I develop it on Linux.
How can I do that?

chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

5

Wednesday, June 15th 2005, 7:59pm

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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
bool open_browser(QWidget* parent, const QString& rUrl)
{
    bool result = false;
    QApplication::setOverrideCursor(Qt::BusyCursor);
#ifdef Q_WS_WIN
    result = int(ShellExecuteW(parent->winId(),
            0,
            rUrl.ucs2(),
            0,
	    0,
	    SW_SHOWNORMAL)) > 32;
#else
    Q_UNUSED(parent);
    // Try a range of browsers available on UNIX, until we (hopefully)
    // find one that works.  Start with the most popular first.
    
    QProcess process;
    bool process_started = false;
    process.setArguments(QStringList() << "netscape" << rUrl);

    process_started = process.start();
    
    if (!process_started)
    {
        process.setArguments(QStringList() << "mozilla" << rUrl);
        
        process_started = process.start();
    }
    if (!process_started)
    {
        process.setArguments(QStringList() << "firefox" << rUrl);
        
        process_started = process.start();
    }
    if (!process_started)
    {
        process.setArguments(QStringList() << "konqueror" << rUrl);
        
        process_started = process.start();
    }
    result = process_started;
#endif
    QApplication::restoreOverrideCursor();
    
    return result;
}
I have enough sense to know that "common sense" is an oxymoron.

Latem

Intermediate

  • "Latem" is male

Posts: 278

Location: New Brunswick, Canada

Occupation: Student/Programmer

  • Send private message

6

Wednesday, June 15th 2005, 9:56pm

In addition to chickenblood's suggestion, sometimes the user may have the $BROWSER variable setup that holds the "default" browser.

You can have an option for the user to set what browser they want to use. Many Linux apps do this, like QtAssistant (good source code here), Akregator, etc... It has the benefit that it provides the user with control of setting that. For example, with the code above, your app will always open my mozilla browser (since it comes first), even though I may prefer firefox, or konqueror, which I also have. And there is no way for me to alter this behaviour.

Ofcourse, you can have an option and the above code. If the option isn't set, try above, and give up if you dont find a browser. If the user has a browser option set, open the prefered browser.

Under Linix, there really isn't such a thing as "the default browser".

Latem
The march of progress:
C:
printf("%10.2f", x);
C++:
cout << setw(10) << setprecision(2) << showpoint << x;
Java:
java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++) System.out.print(' ');
System.out.print(s);

This post has been edited 1 times, last edit by "Latem" (Jun 15th 2005, 9:58pm)


Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

7

Thursday, June 16th 2005, 2:29pm

Maybe you can just use QTextBrowser or Qt Assistant on system witout launcher API.

(actually only plain X11 doesn't have a launcher API, higher level platforms like KDE or GNOME do)

Cheers,
_
Qt/KDE Developer
Debian User

Barney`

Beginner

  • "Barney`" is male

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

8

Sunday, June 19th 2005, 7:47pm

via_mainwindow.ui.h:258: error: `BusyCursor' is not a member of type `Qt'
via_mainwindow.ui.h:294: error: return-statement with a value, in function declared with a void return type

:/

I don't (really) understand the function so I paste it in my file and modified it to adapt it with my project but there are still these 2 errors.

This post has been edited 1 times, last edit by "Barney`" (Jun 19th 2005, 8:18pm)


chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

9

Sunday, June 19th 2005, 9:54pm

Quoted

Originally posted by Barney`
via_mainwindow.ui.h:258: error: `BusyCursor' is not a member of type `Qt'
via_mainwindow.ui.h:294: error: return-statement with a value, in function declared with a void return type

:/

I don't (really) understand the function so I paste it in my file and modified it to adapt it with my project but there are still these 2 errors.

Qt::BusyCursor was introduced in later versions of the Qt 3.x series than the one that you are using (probably). Try Qt::WaitCursor instead. These lines are not mandatory, so you could remove them completely anyway. Also, did you copy the function correctly? Check that the return type is 'bool' and not 'void'
I have enough sense to know that "common sense" is an oxymoron.

Barney`

Beginner

  • "Barney`" is male

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

10

Sunday, June 19th 2005, 10:40pm

By the way, what's the point in returning a boolean instead of a void function?

chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

11

Sunday, June 19th 2005, 10:59pm

Quoted

Originally posted by Barney`
By the way, what's the point in returning a boolean instead of a void function?

Ahem.
So the caller of the function knows whether it was succesful or not, i.e. 'was a browser succesfully opened'?
I have enough sense to know that "common sense" is an oxymoron.

Barney`

Beginner

  • "Barney`" is male

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

12

Monday, June 20th 2005, 10:10pm

It compiled with WaitCursor but I've these 2 errors while excecuting :

QObject::connect: No such slot VIA::helpContents(this,"/home/donkey/Desktop/via_project/help/help_general.htm")
QObject::connect: (sender name: 'helpContentsAction')
QObject::connect: (receiver name: 'VIA')

and of course, nothing happens.

What does correspond to the parameter "parent"? (I put 'this' :P)

This post has been edited 1 times, last edit by "Barney`" (Jun 20th 2005, 10:11pm)


chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

13

Monday, June 20th 2005, 11:21pm

Quoted

Originally posted by Barney`
It compiled with WaitCursor but I've these 2 errors while excecuting :

QObject::connect: No such slot VIA::helpContents(this,"/home/donkey/Desktop/via_project/help/help_general.htm")
QObject::connect: (sender name: 'helpContentsAction')
QObject::connect: (receiver name: 'VIA')

and of course, nothing happens.

So check your connection! Is helpContents() properly declared as a slot? Does VIA contain the Q_OBJECT macro? Does it's argument list match the signal being emitted (I suspect not, since you are connecting it to an action and QActions do not emit any signal that has a QString parameter). In short make sure you understand signals and slots and use them correctly[i].

Quoted


What does correspond to the parameter "parent"? (I put 'this' :P)

On UNIX/Linux, it is not used, on Windows it is used as an "owner" window for the browser that is launched. Any toplevel widget will do for this.
I have enough sense to know that "common sense" is an oxymoron.

14

Saturday, December 10th 2005, 1:02am

Since I haven't been able to get this to work and some of the methods and variable types described don't even exist for me, I'm going to assume that most, if not all, of everything above is for Qt3.

Does anyone have a windowsxp, Qt4, method for launching the default webbrowser? I've banged my head against the wall for a couple days now so it's too late for me to feel stupid for having to ask :-).

Thanks all.

[edit]I've found two similar methods that work:

Source code

1
2
3
4
    #ifdef _WIN32
        //openPage.startDetached( "cmd", QStringList() << "/c" << "start" << url.toString() );
        //openPage.waitForFinished();
        openPage.execute( QString( "rundll32 url.dll,FileProtocolHandler \"%1\"" ).arg( url.toString() ) );


But there is a severe lag in the webbrowser starting up during which time my program is locked up. Even if the program wasn't locked up, the lagtime( 30-45 seconds) would be way too much. QProcess is apparently causing this lagtime (since the rundll32 command starts instantly from the command line when I type it in by hand), although I don't have QProcess lag issues in executing other external executables.

What is causing the QProcess lag with browser related commands? Please, any help will be greatly appreciated!
Qt 4.0.1, Windows XP, MinGW

This post has been edited 3 times, last edit by "DanielHutchison" (Dec 10th 2005, 2:16am)