0

I'm a beginner.I am making a simple gui program using qt in which you enter a url/website and that program will open that webpage in chrome.I used line edit in which user enters url and i used returnPressed() slot, but the problem is (it might sound stupid) that i don't know how to take the input by user and store it in a string so that i can pass that string as parameter to chrome.Is im asking something wrong.also tell me how can i save input to a txt file, i know how to do that in a console program.Is this process is same with others like text edit etc.
My mainwindow.cpp:

    QString exeloc = "F:\\Users\\Amol-2\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";

void MainWindow::on_site_returnPressed()
{
    QString site;
    getwchar(site);
    QString space=" ";
    QString result = exeloc + space + site;
    QProcess::execute(result);

}

What im doing wrong.
thanks

Amol Borkar
  • 2,321
  • 7
  • 32
  • 63

2 Answers2

1

You've got your approach slightly wrong, I can see where you're coming from though. It's actually a lot more simple than you're trying, Qt has a QDesktopServices class that allows you to interact with various system items, including open urls in the browser. There's documentation on it here.

Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55
0

QLineEdit has a text() function that will return a QString. So you can do something like this:

QString site = ui->site->text();

You don't have to use QProcess to open a web site in a browser. You can use QDesktopServices::openUrl static function.

Like this:

QString site = ui->site->text();
QUrl url(site);
QDesktopServices::openUrl(url);

Remember to include QDesktopServices and QUrl headers:

#include <QDesktopServices>
#include <QUrl>
thuga
  • 12,601
  • 42
  • 52
  • hey its giving me the followingF:\Users\Amol-2\Desktop\Imp Docs\C++ apps\QtMainLProject\mainwindow.cpp:27: error: variable 'QUrl url' has initializer but incomplete type QUrl url(site); what should i do now ^ character:
    – Amol Borkar Jan 30 '14 at 11:24
  • @user3251645 `#include ` – thuga Jan 30 '14 at 11:31