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. Set editline text to path?
Forum Updated to NodeBB v4.3 + New Features

Set editline text to path?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.9k 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.
  • G Offline
    G Offline
    glowdemon1
    wrote on last edited by
    #1

    So I have 2 GUIS, one directory browser and one main GUI, on the main GUI there's a line edit. Whenever I go to directory browser, select a directory and then click a button, the path should appear on the line edit, but it doesn't. It doesnt, can someone please check what I did wrong?

    from directoryexplorer.cpp
    @void directoryExplorer::on_selectButton_clicked()
    {
    if(ui->treeView->selectionModel()->hasSelection()){
    QModelIndex i = ui->treeView->selectionModel()->currentIndex();
    QString path = mmodel->fileInfo(i).absoluteFilePath();
    MainWindow o;
    o.fillInOutput(path);
    }
    }@

    from mainwindow.cpp
    @void MainWindow::fillInOutput(QString fpath){
    ui->lineEditOutput->setText(fpath);
    }
    @

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Of course it doesn't work like that.
      @
      MainWindow o; //o is a local variable, not your main window
      o.fillInOutput(path);
      } //o is destroyed here.
      @
      This sounds like a job for signals and slots. In your directoryExplorer header add signal:
      @signals:
      void pathChanged(QString);
      @
      and replace the code above with
      @emit pathChanged(path);
      @
      In the main window connect to that signal:
      connect(<yourDirExplorerPointer>, directoryExplorer::pathChanged, this, MainWindow::fillInOutput);

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glowdemon1
        wrote on last edited by
        #3

        [quote author="Chris Kawa" date="1397316003"]Of course it doesn't work like that.
        @
        MainWindow o; //o is a local variable, not your main window
        o.fillInOutput(path);
        } //o is destroyed here.
        @
        This sounds like a job for signals and slots. In your directoryExplorer header add signal:
        @signals:
        void pathChanged(QString);
        @
        and replace the code above with
        @emit pathChanged(path);
        @
        In the main window connect to that signal:
        connect(<yourDirExplorerPointer>, directoryExplorer::pathChanged, this, MainWindow::fillInOutput);[/quote]

        Thanks but I don't understand the last instruction. I wrote
        connect(<de>, directoryExplorer::pathChanged, this, MainWindow::fillInOutput);

        because I'm sure that's my pointer, is it not? I wrote it in the header like this : directoryExplorer de;

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I meant <yourDirExplorerPointer> as a placeholder, sorry.

          connect() expects a pointer so in your case, since you have a stack variable de, you need to pass its address:
          @connect(&de, directoryExplorer::pathChanged, this, MainWindow::fillInOutput);@

          The call to connect should be placed in an initializing function of your MainWindow eg. in the constructor.

          I think it would be good for you to get back to some C++ basics before you start with Qt. It's only going to get harder. Without knowing what pointers are or what a variable scope will be you're gonna struggle a lot.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            glowdemon1
            wrote on last edited by
            #5

            [quote author="Chris Kawa" date="1397323784"]I meant <yourDirExplorerPointer> as a placeholder, sorry.

            connect() expects a pointer so in your case, since you have a stack variable de, you need to pass its address:
            @connect(&de, directoryExplorer::pathChanged, this, MainWindow::fillInOutput);@

            The call to connect should be placed in an initializing function of your MainWindow eg. in the constructor.

            I think it would be good for you to get back to some C++ basics before you start with Qt. It's only going to get harder. Without knowing what pointers are or what a variable scope will be you're gonna struggle a lot.[/quote]

            Yeah probably, I watched most of thenewboston's tutorials (skipped the last 15) but I keep on forgetting about everything, I should probably pick up a book rather than watching videos

            1 Reply Last reply
            0
            • X Offline
              X Offline
              Xander84
              wrote on last edited by
              #6

              Chris: I think you need to get the pointer of the class member function for the connect to work?
              @
              &directoryExplorer::pathChanged
              @
              instead of
              @
              directoryExplorer::pathChanged
              @
              ?

              I've also told glowdemon1 to learn the c++ basics first (in another thread), it will certainly help. and I think you should also learn how to interpret compiler errors, because most of your problems are syntax errors and show during compilation.

              Btw: how can i escape the at-sign in this forum? lol

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Xander84 - yeah, of course, sorry for that. My mind was somewhere else when I typed that.

                The formatting on this forum is the most mind-boggling thing ever.
                It's suppose to be "textile":http://qt-project.org/wiki/TextileSyntax but not really :P
                To use @ in your text you can either have just one in the whole text or use html entity: &#64;
                Also, if you use @ inside a code tag without whitespace like this:
                @a@b@c@ it will use the outer ones for code and the inner ones as text. If you have couple of them next to each other neighbored by a character eg. a@@@ it will print them all.
                I would love to see the code for that parser one day :P

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  Xander84
                  wrote on last edited by
                  #8

                  Thanks for the formatting explanation, I would expect to just write @@ to "escape" it or something easy but it didn't work. :D

                  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