Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] I need the logic to pass data from one function to another to avoid global functions
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] I need the logic to pass data from one function to another to avoid global functions

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 521 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fs_tigre
    wrote on last edited by
    #1

    Hi,

    I have a situation here that I cannot figure it out, ok let me re-phrase this, I could easily do this using a global variable but I'm trying to avoid it at all cost.

    What I have is a function which does two things, looks for a file in a bunch of directories and if it finds the file, it returns TURE and also sets a reference variable with the URL where the file was found...

    @// here is the searching function
    bool MainWindow::findFile(QString &URL)
    {
    // searches for file...
    }@

    ...then I'm calling the function above in a second function where I'm setting some parameters if the file was found, and here is where my problem starts since I don't really need to set the URL in this function, here I only need to know whether the file was found or not; I need the URL to be set in a third function which will open the file when a button is clicked.

    @// here I'm using another reference variable to get the URL out since
    // it is not needed here
    void MainWindow::doesFileExists(QString &setURL)
    {
    // I don't really need this here, I need it in another function
    QString getURL;
    findFile(getURL)

    setURL = getURL;

    if (findFile)
    {
    // set some parameters...
    }
    }@

    ... then I'm finally setting the URL in a third function where I originally wanted it

    @void MainWindow::on_pushButton_openFile()
    {
    QString getPath;
    doesFileExists(getPath)
    QDesktopServices::openUrl(QUrl("file:///"+ getPath));
    }@

    The above code works fine the only problem which to me is a huge problem, is the fact that I would like to search for the file only once and the way I currently have it it's searching for the file when calling the first function and every time the on_pushButton_openFile() function is called.

    In theory waht I really want to do is to be able to search for a file and if the file is found, set a QLabel to true to let the user know the result and also to set the URL so that if the user ever decides to open the file the program doesn't have to search for the file again.

    I hope that what I describe above makes sense.

    Thanks a lot.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved